diff --git a/admin/bloglevelupgrade.php b/admin/bloglevelupgrade.php
index f833c176915a2..b04d1dc46d199 100644
--- a/admin/bloglevelupgrade.php
+++ b/admin/bloglevelupgrade.php
@@ -48,7 +48,7 @@
$a->blogcount = 0;
foreach ($bloggers as $blogger) {
- $courses = get_my_courses($blogger->userid);
+ $courses = enrol_get_users_courses($blogger->userid, true, 'groupmode,groupmodeforce');
$blogentries = $DB->get_records('post', array('module' => 'blog', 'userid' => $blogger->userid));
foreach ($courses as $course) {
diff --git a/admin/cron.php b/admin/cron.php
index ef41ce01e4643..79def22767d4f 100644
--- a/admin/cron.php
+++ b/admin/cron.php
@@ -205,34 +205,6 @@
}
mtrace('Finished admin reports');
- mtrace('Removing expired enrolments ...', ''); // See MDL-8785
- $timenow = time();
- $somefound = false;
- // The preferred way saves memory, datablib
- // find courses where limited enrolment is enabled
- $sql = "SELECT ra.roleid, ra.userid, ra.contextid
- FROM {course} c
- JOIN {context} cx ON cx.instanceid = c.id
- JOIN {role_assignments} ra ON ra.contextid = cx.id
- WHERE cx.contextlevel = '".CONTEXT_COURSE."'
- AND ra.timeend > 0
- AND ra.timeend < ?
- AND c.enrolperiod > 0";
- if ($rs = $DB->get_recordset_sql($sql, array($timenow))) {
- foreach ($rs as $oldenrolment) {
- role_unassign($oldenrolment->roleid, $oldenrolment->userid, 0, $oldenrolment->contextid);
- $somefound = true;
- }
- $rs->close();
- }
- if ($somefound) {
- mtrace('Done');
- } else {
- mtrace('none found');
- }
-
-
-
mtrace('Starting main gradebook job ...');
grade_cron();
mtrace('done.');
@@ -270,41 +242,6 @@
if ($random100 < 20) { // Approximately 20% of the time.
mtrace("Running clean-up tasks...");
- /// Unenrol users who haven't logged in for $CFG->longtimenosee
-
- if ($CFG->longtimenosee) { // value in days
- $cuttime = $timenow - ($CFG->longtimenosee * 3600 * 24);
- $rs = $DB->get_recordset_sql ("SELECT id, userid, courseid
- FROM {user_lastaccess}
- WHERE courseid != ".SITEID."
- AND timeaccess < ?", array($cuttime));
- foreach ($rs as $assign) {
- if ($context = get_context_instance(CONTEXT_COURSE, $assign->courseid)) {
- if (role_unassign(0, $assign->userid, 0, $context->id)) {
- mtrace("removing user $assign->userid from course $assign->courseid as they have not accessed the course for over $CFG->longtimenosee days");
- }
- }
- }
- $rs->close();
- /// Execute the same query again, looking for remaining records and deleting them
- /// if the user hasn't moodle/course:participate in the CONTEXT_COURSE context (orphan records)
- $rs = $DB->get_recordset_sql ("SELECT id, userid, courseid
- FROM {user_lastaccess}
- WHERE courseid != ".SITEID."
- AND timeaccess < ?", array($cuttime));
- foreach ($rs as $assign) {
- if ($context = get_context_instance(CONTEXT_COURSE, $assign->courseid)) {
- if (!is_enrolled($context, $assign->userid) and !is_viewing($context, $assign->userid)) {
- $DB->delete_records('user_lastaccess', array('userid'=>$assign->userid, 'courseid'=>$assign->courseid));
- mtrace("Deleted orphan user_lastaccess for user $assign->userid from course $assign->courseid");
- }
- }
- }
- $rs->close();
- }
- flush();
-
-
/// Delete users who haven't confirmed within required period
if (!empty($CFG->deleteunconfirmed)) {
@@ -370,9 +307,6 @@
}
flush();
- sync_metacourses();
- mtrace('Synchronised metacourses');
-
//
// generate new password emails for users
//
@@ -464,20 +398,16 @@
unset($authplugin);
}
-/// Run the enrolment cron, if any
- if (!($plugins = explode(',', $CFG->enrol_plugins_enabled))) {
- $plugins = array($CFG->enrol);
- }
- require_once($CFG->dirroot .'/enrol/enrol.class.php');
- foreach ($plugins as $p) {
- $enrol = enrolment_factory::factory($p);
- if (method_exists($enrol, 'cron')) {
- $enrol->cron();
- }
- if (!empty($enrol->log)) {
- mtrace($enrol->log);
+ mtrace("Running enrol crons if required...");
+ $enrols = enrol_get_plugins(true);
+ foreach($enrols as $ename=>$enrol) {
+ // do this for all plugins, disabled plugins might want to cleanup stuff such as roles
+ if (!$enrol->is_cron_required()) {
+ continue;
}
- unset($enrol);
+ mtrace("Running cron for enrol_$ename...");
+ $enrol->cron();
+ $enrol->set_config('lastcron', time());
}
if (!empty($CFG->enablestats) and empty($CFG->disablestatsprocessing)) {
diff --git a/admin/enrol.php b/admin/enrol.php
index 0bd4866c760f6..26e430ef8f707 100644
--- a/admin/enrol.php
+++ b/admin/enrol.php
@@ -1,141 +1,120 @@
libdir.'/adminlib.php');
-
- $enrol = optional_param('enrol', $CFG->enrol, PARAM_SAFEDIR);
- $savesettings = optional_param('savesettings', 0, PARAM_BOOL);
-
- admin_externalpage_setup('enrolment');
-
- if (!isset($CFG->sendcoursewelcomemessage)) {
- set_config('sendcoursewelcomemessage', 1);
- }
-
-
- require_once("$CFG->dirroot/enrol/enrol.class.php"); /// Open the factory class
-
-/// Save settings
-
- if ($frm = data_submitted() and !$savesettings) {
- if (!confirm_sesskey()) {
- print_error('confirmsesskeybad', 'error');
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see
Each course has one default enrolment role specified. Please make sure no risky capabilities are allowed for this role.
-The only supported legacy type for the default course role is Student.
'; -$string['check_courserole_error'] = 'Incorrectly defined default course roles detected!'; -$string['check_courserole_name'] = 'Default roles (courses)'; -$string['check_courserole_notyet'] = 'Used only default course role.'; -$string['check_courserole_ok'] = 'Default course role definitions is OK.'; -$string['check_courserole_risky'] = 'Risky capabilities detected in context.'; -$string['check_courserole_riskylegacy'] = 'Risky legacy type detected in {$a->shortname}.'; -$string['check_defaultcourserole_anything'] = 'The "doanything" capability must not be allowed in this context.'; -$string['check_defaultcourserole_details'] = 'The default student role for course enrolment specifies the default role for courses. Please make sure no risky capabilities are allowed in this role.
-The only supported legacy type for default role is Student.
'; -$string['check_defaultcourserole_error'] = 'Incorrectly defined default course role "{$a}" detected!'; -$string['check_defaultcourserole_legacy'] = 'Risky legacy type detected.'; -$string['check_defaultcourserole_name'] = 'Default course role (global)'; -$string['check_defaultcourserole_notset'] = 'Default role is not set.'; -$string['check_defaultcourserole_ok'] = 'Site default role definition is OK.'; -$string['check_defaultcourserole_risky'] = 'Risky capabilities detected in context.'; $string['check_defaultuserrole_details'] = 'All logged in users are given capabilities of the default user role. Please make sure no risky capabilities are allowed in this role.
The only supported legacy type for the default user role is Authenticated user. The course view capability must not be enabled.
'; $string['check_defaultuserrole_error'] = 'The default user role "{$a}" is incorrectly defined!'; diff --git a/admin/report/security/lib.php b/admin/report/security/lib.php index 2d59c764369f7..b3053ffab8ff5 100644 --- a/admin/report/security/lib.php +++ b/admin/report/security/lib.php @@ -58,8 +58,6 @@ function report_security_get_issue_list() { 'report_security_check_defaultuserrole', 'report_security_check_guestrole', 'report_security_check_frontpagerole', - 'report_security_check_defaultcourserole', - 'report_security_check_courserole', ); } @@ -587,9 +585,6 @@ function report_security_check_defaultuserrole($detailed=false) { $riskycount = $DB->count_records_sql($sql, $params); - // default role can not have view cap in all courses - this would break moodle badly - $viewcap = $DB->record_exists('role_capabilities', array('roleid'=>$default_role->id, 'permission'=>CAP_ALLOW, 'capability'=>'moodle/course:participate')); - // it may have either none or 'user' archetype - nothing else, or else it would break during upgrades badly if ($default_role->archetype === '' or $default_role->archetype === 'user') { $legacyok = true; @@ -597,7 +592,7 @@ function report_security_check_defaultuserrole($detailed=false) { $legacyok = false; } - if ($riskycount or $viewcap or !$legacyok) { + if ($riskycount or !$legacyok) { $result->status = REPORT_SECURITY_CRITICAL; $result->info = get_string('check_defaultuserrole_error', 'report_security', format_string($default_role->name)); @@ -730,190 +725,6 @@ function report_security_check_frontpagerole($detailed=false) { return $result; } -/** - * Verifies sanity of site default course role. - * @param bool $detailed - * @return object result - */ -function report_security_check_defaultcourserole($detailed=false) { - global $DB, $CFG; - - $problems = array(); - - $result = new object(); - $result->issue = 'report_security_check_defaultcourserole'; - $result->name = get_string('check_defaultcourserole_name', 'report_security'); - $result->info = null; - $result->details = null; - $result->status = null; - $result->link = "wwwroot/$CFG->admin/settings.php?section=userpolicies\">".get_string('userpolicies', 'admin').'';; - - if ($detailed) { - $result->details = get_string('check_defaultcourserole_details', 'report_security'); - } - - if (!$student_role = $DB->get_record('role', array('id'=>$CFG->defaultcourseroleid))) { - $result->status = REPORT_SECURITY_WARNING; - $result->info = get_string('check_defaultcourserole_notset', 'report_security'); - $result->details = get_string('check_defaultcourserole_details', 'report_security'); - - return $result; - } - - // risky caps - usually very dangerous - $params = array('capallow'=>CAP_ALLOW, 'roleid'=>$student_role->id); - $sql = "SELECT DISTINCT rc.contextid - FROM {role_capabilities} rc - JOIN {capabilities} cap ON cap.name = rc.capability - WHERE ".$DB->sql_bitand('cap.riskbitmask', (RISK_XSS | RISK_CONFIG | RISK_DATALOSS))." <> 0 - AND rc.permission = :capallow - AND rc.roleid = :roleid"; - - if ($riskycontexts = $DB->get_records_sql($sql, $params)) { - foreach($riskycontexts as $contextid=>$unused) { - if ($contextid == SYSCONTEXTID) { - $a = "$CFG->wwwroot/$CFG->admin/roles/define.php?action=view&roleid=$CFG->defaultcourseroleid"; - } else { - $a = "$CFG->wwwroot/$CFG->admin/roles/override.php?contextid=$contextid&roleid=$CFG->defaultcourseroleid"; - } - $problems[] = get_string('check_defaultcourserole_risky', 'report_security', $a); - } - } - - // course creator or administrator does not make any sense here - if ($student_role->archetype === 'coursecreator' or $student_role->archetype === 'manager') { - $problems[] = get_string('check_defaultcourserole_legacy', 'report_security'); - } - - if ($problems) { - $result->status = REPORT_SECURITY_CRITICAL; - $result->info = get_string('check_defaultcourserole_error', 'report_security', format_string($student_role->name)); - if ($detailed) { - $result->details .= "
-
-
' . get_string('safeoverridenotice', 'role') . "
\n"; diff --git a/admin/roles/permissions.php b/admin/roles/permissions.php index cbd2ee6c0ff2f..bfdd13759439f 100644 --- a/admin/roles/permissions.php +++ b/admin/roles/permissions.php @@ -75,7 +75,6 @@ $contextname = print_context_name($context); $title = get_string('permissionsincontext', 'role', $contextname); $straction = get_string('permissions', 'role'); // Used by tabs.php -$tabfile = $CFG->dirroot.'/'.$CFG->admin.'/roles/tabs.php'; $currenttab = 'permissions'; $PAGE->set_pagelayout('admin'); @@ -85,7 +84,6 @@ print_error('cannotoverridebaserole', 'error'); break; case CONTEXT_USER: - $tabfile = null; if ($isfrontpage) { $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context)); $PAGE->set_heading($fullname); @@ -143,9 +141,6 @@ } // Display and print echo $OUTPUT->header(); - if ($tabfile) { - include($tabfile); - } echo $OUTPUT->heading($title); echo $OUTPUT->confirm($message, $continueurl, $PAGE->url); echo $OUTPUT->footer(); @@ -184,9 +179,6 @@ } } echo $OUTPUT->header(); - if ($tabfile) { - include($tabfile); - } echo $OUTPUT->heading($title); echo $OUTPUT->box($message); $mform->display(); @@ -196,9 +188,6 @@ } echo $OUTPUT->header(); -if ($tabfile) { - include($tabfile); -} echo $OUTPUT->heading($title); $table = new permissions_table($context, $contextname, $allowoverrides, $allowsafeoverrides, $overridableroles); diff --git a/admin/roles/tabs.php b/admin/roles/tabs.php deleted file mode 100755 index 6c69a06efb990..0000000000000 --- a/admin/roles/tabs.php +++ /dev/null @@ -1,116 +0,0 @@ -. - -/** - * Handles headers and tabs for the roles control at any level apart from SYSTEM level - * We assume that $currenttab, $assignableroles and $overridableroles are defined - * - * @package moodlecore - * @subpackage role - * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -if (!defined('MOODLE_INTERNAL')) { - die('Direct access to this script is forbidden.'); // It must be included from a Moodle page -} - -if (!isset($availablefilters)) { - $availablefilters = array(); - if (in_array($context->contextlevel, array(CONTEXT_COURSECAT, CONTEXT_COURSE, CONTEXT_MODULE)) && - !($context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID) && - has_capability('moodle/filter:manage', $context)) { - $availablefilters = filter_get_available_in_context($context); - } -} - -$toprow = array(); -$inactive = array(); -$activetwo = array(); -$secondrow = array(); - -$permissionsrow = array(); - -if ($context->contextlevel != CONTEXT_SYSTEM) { // Print tabs for anything except SYSTEM context - - if ($context->contextlevel == CONTEXT_MODULE) { // Only show update button if module - $url = new moodle_url('/course/mod.php', array('update'=>$context->instanceid, 'return'=>'true', 'sesskey'=>sesskey())); - $toprow[] = new tabobject('update', $url, get_string('settings')); - } - - if (!empty($assignableroles) || $currenttab=='assign') { - $url = new moodle_url('/admin/roles/assign.php', array('contextid'=>$context->id)); - $toprow[] = new tabobject('assign', $url, get_string('localroles', 'role'), '', true); - } - - if (has_capability('moodle/role:review', $context) or !empty($overridableroles)) { - $url = new moodle_url('/admin/roles/permissions.php', array('contextid'=>$context->id)); - $permissionsrow['permissions'] = new tabobject('permissions', $url, get_string('permissions', 'role'), '', true); - } - - if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:assign'), $context)) { - $url = new moodle_url('/admin/roles/check.php', array('contextid'=>$context->id)); - $permissionsrow['check'] = new tabobject('check', $url, get_string('checkpermissions', 'role')); - } - - if ($permissionsrow) { - $firstpermissionrow = reset($permissionsrow); - $toprow[] = new tabobject('toppermissions', $firstpermissionrow->link, get_string('permissions', 'role'), '', true); - if (!empty($permissionsrow[$currenttab])) { - $secondrow = array_values($permissionsrow); - $inactive = array('toppermissions'); - $activetwo = array('toppermissions'); - } - } - - if (!empty($availablefilters)) { - $url = new moodle_url('/filter/manage.php', array('contextid'=>$context->id)); - $toprow[] = new tabobject('filters', $url, get_string('filters', 'admin')); - } -} -unset($permissionsrow); - -/// Here other core tabs should go (always calling tabs.php files) -/// All the logic to decide what to show must be self-contained in the tabs file -/// eg: -/// include_once($CFG->dirroot . '/grades/tabs.php'); - -/// Finally, we support adding some 'on-the-fly' tabs here -/// All the logic to decide what to show must be self-cointained in the tabs file -if (!empty($CFG->extratabs)) { - if ($extratabs = explode(',', $CFG->extratabs)) { - asort($extratabs); - foreach($extratabs as $extratab) { - /// Each extra tab must be one $CFG->dirroot relative file - if (file_exists($CFG->dirroot . '/' . $extratab)) { - include($CFG->dirroot . '/' . $extratab); - } - } - } -} - -$inactive[] = $currenttab; - -$tabs = array($toprow); - -/// If there are any secondrow defined, let's introduce it -if (!empty($secondrow)) { - $tabs[] = $secondrow; -} - -print_tabs($tabs, $currenttab, $inactive, $activetwo); - diff --git a/admin/roles/usersroles.php b/admin/roles/usersroles.php index a25d6ddbde707..7412c89f14fa2 100644 --- a/admin/roles/usersroles.php +++ b/admin/roles/usersroles.php @@ -55,7 +55,7 @@ /// Now get the role assignments for this user. $sql = "SELECT - ra.id, ra.userid, ra.contextid, ra.roleid, ra.enrol, + ra.id, ra.userid, ra.contextid, ra.roleid, ra.component, ra.itemid c.path, r.name AS rolename, COALESCE(rn.name, r.name) AS localname diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index 464784232d992..65106dc0f5638 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -135,9 +135,9 @@ $temp = new admin_externalpage('profilepage', get_string('myprofile', 'admin'), $CFG->wwwroot . '/user/profilesys.php'); $ADMIN->add('appearance', $temp); - // coursemanager is the person responsible for course - usually manages enrolments, receives notification, etc. - $temp = new admin_settingpage('coursemanager', get_string('coursemanager', 'admin')); - $temp->add(new admin_setting_special_coursemanager()); + // coursecontact is the person responsible for course - usually manages enrolments, receives notification, etc. + $temp = new admin_settingpage('coursecontact', get_string('coursecontact', 'admin')); + $temp->add(new admin_setting_special_coursecontact()); $ADMIN->add('appearance', $temp); $temp = new admin_settingpage('ajax', get_string('ajaxuse')); diff --git a/admin/settings/courses.php b/admin/settings/courses.php index e1e7504dbd8bb..291941395478a 100644 --- a/admin/settings/courses.php +++ b/admin/settings/courses.php @@ -11,8 +11,6 @@ $ADMIN->add('courses', new admin_externalpage('coursemgmt', get_string('coursemgmt', 'admin'), $CFG->wwwroot . '/course/index.php?categoryedit=on', array('moodle/category:manage', 'moodle/course:create'))); - $ADMIN->add('courses', new admin_enrolment_page()); - /// Course Default Settings Page /// NOTE: these settings must be applied after all other settings because they depend on them ///main course settings @@ -41,45 +39,6 @@ $choices = get_max_upload_sizes(); } $temp->add(new admin_setting_configselect('moodlecourse/maxbytes', get_string('maximumupload'), get_string('coursehelpmaximumupload'), key($choices), $choices)); - $temp->add(new admin_setting_configselect('moodlecourse/metacourse', get_string('metacourse'), get_string('coursehelpmetacourse'), 0,array(0 => get_string('no'), 1 => get_string('yes')))); - - ///enrolement course settings - $temp->add(new admin_setting_heading('enrolhdr', get_string('enrolments'), '')); - require_once($CFG->dirroot.'/enrol/enrol.class.php'); - $choices = array(); - $modules = explode(',', $CFG->enrol_plugins_enabled); - foreach ($modules as $module) { - $name = get_string('enrolname', "enrol_$module"); - $plugin = enrolment_factory::factory($module); - if (method_exists($plugin, 'print_entry')) { - $choices[$name] = $module; - } - } - asort($choices); - $choices = array_flip($choices); - $choices = array_merge(array('' => get_string('sitedefault').' ('.get_string('enrolname', "enrol_$CFG->enrol").')'), $choices); - $temp->add(new admin_setting_configselect('moodlecourse/enrol', get_string('enrolmentplugins'), get_string('coursehelpenrolmentplugins'), key($choices),$choices)); - $choices = array(0 => get_string('no'), 1 => get_string('yes'), 2 => get_string('enroldate')); - $temp->add(new admin_setting_configselect('moodlecourse/enrollable', get_string('enrollable'), get_string('coursehelpenrollable'), 1,$choices)); - $periodmenu=array(); - $periodmenu[0] = get_string('unlimited'); - for ($i=1; $i<=365; $i++) { - $seconds = $i * 86400; - $periodmenu[$seconds] = get_string('numdays', '', $i); - } - $temp->add(new admin_setting_configselect('moodlecourse/enrolperiod', get_string('enrolperiod'), '', 0,$periodmenu)); - - /// - $temp->add(new admin_setting_heading('expirynotifyhdr', get_string('expirynotify'), '')); - $temp->add(new admin_setting_configselect('moodlecourse/expirynotify', get_string('notify'), get_string('coursehelpnotify'), 0,array(0 => get_string('no'), 1 => get_string('yes')))); - $temp->add(new admin_setting_configselect('moodlecourse/notifystudents', get_string('expirynotifystudents'), get_string('coursehelpexpirynotifystudents'), 0,array(0 => get_string('no'), 1 => get_string('yes')))); - $thresholdmenu=array(); - for ($i=1; $i<=30; $i++) { - $seconds = $i * 86400; - $thresholdmenu[$seconds] = get_string('numdays', '', $i); - } - $temp->add(new admin_setting_configselect('moodlecourse/expirythreshold', get_string('expirythreshold'), get_string('coursehelpexpirythreshold'), 10 * 86400,$thresholdmenu)); - $temp->add(new admin_setting_heading('groups', get_string('groups', 'group'), '')); $choices = array(); @@ -95,12 +54,6 @@ $choices['0'] = get_string('courseavailablenot'); $choices['1'] = get_string('courseavailable'); $temp->add(new admin_setting_configselect('moodlecourse/visible', get_string('visible'), '', 1,$choices)); - $temp->add(new admin_setting_configpasswordunmask('moodlecourse/enrolpassword', get_string('enrolmentkey'), get_string('coursehelpenrolmentkey'),'')); - $choices = array(); - $choices['0'] = get_string('guestsno'); - $choices['1'] = get_string('guestsyes'); - $choices['2'] = get_string('guestskey'); - $temp->add(new admin_setting_configselect('moodlecourse/guest', get_string('opentoguests'), '', 0,$choices)); $temp->add(new admin_setting_heading('language', get_string('language'), '')); @@ -151,7 +104,6 @@ $temp = new admin_settingpage('scheduled', get_string('scheduledsettings','backup'), 'moodle/backup:backupcourse'); $temp->add(new admin_setting_configcheckbox('backup/backup_sche_modules', get_string('includemodules'), get_string('backupincludemoduleshelp'), 0)); $temp->add(new admin_setting_configcheckbox('backup/backup_sche_withuserdata', get_string('includemoduleuserdata'), get_string('backupincludemoduleuserdatahelp'), 0)); - $temp->add(new admin_setting_configcheckbox('backup/backup_sche_metacourse', get_string('metacourse'), get_string('backupmetacoursehelp'), 0)); $temp->add(new admin_setting_configselect('backup/backup_sche_users', get_string('users'), get_string('backupusershelp'), 0, array(0 => get_string('all'), 1 => get_string('course')))); $temp->add(new admin_setting_configcheckbox('backup/backup_sche_logs', get_string('logs'), get_string('backuplogshelp'), 0)); diff --git a/admin/settings/frontpage.php b/admin/settings/frontpage.php index 24a537689fe24..052611b24b47b 100644 --- a/admin/settings/frontpage.php +++ b/admin/settings/frontpage.php @@ -50,7 +50,6 @@ $temp->add(new admin_setting_configtext('commentsperpage', get_string('commentsperpage', 'admin'), '', 15, PARAM_INT)); $temp->add(new admin_setting_configtext('coursesperpage', get_string('coursesperpage', 'admin'), get_string('configcoursesperpage', 'admin'), 20, PARAM_INT)); - $temp->add(new admin_setting_configcheckbox('allowvisiblecoursesinhiddencategories', get_string('allowvisiblecoursesinhiddencategories', 'admin'), get_string('configvisiblecourses', 'admin'), 0)); // front page default role $roleoptions = array(0=>get_string('none')); // roles to choose from diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php index cf77a1cf0f0db..6168fff65cea2 100644 --- a/admin/settings/plugins.php +++ b/admin/settings/plugins.php @@ -50,6 +50,84 @@ } } + // authentication plugins + $ADMIN->add('modules', new admin_category('authsettings', get_string('authentication', 'admin'))); + + $temp = new admin_settingpage('manageauths', get_string('authsettings', 'admin')); + $temp->add(new admin_setting_manageauths()); + $temp->add(new admin_setting_heading('manageauthscommonheading', get_string('commonsettings', 'admin'), '')); + $temp->add(new admin_setting_special_registerauth()); + $temp->add(new admin_setting_configselect('guestloginbutton', get_string('guestloginbutton', 'auth'), + get_string('showguestlogin', 'auth'), '1', array('0'=>get_string('hide'), '1'=>get_string('show')))); + $temp->add(new admin_setting_configtext('alternateloginurl', get_string('alternateloginurl', 'auth'), + get_string('alternatelogin', 'auth', htmlspecialchars(get_login_url())), '')); + $temp->add(new admin_setting_configtext('forgottenpasswordurl', get_string('forgottenpasswordurl', 'auth'), + get_string('forgottenpassword', 'auth'), '')); + $temp->add(new admin_setting_confightmleditor('auth_instructions', get_string('instructions', 'auth'), + get_string('authinstructions', 'auth'), '')); + $temp->add(new admin_setting_configtext('allowemailaddresses', get_string('allowemailaddresses', 'admin'), get_string('configallowemailaddresses', 'admin'), '', PARAM_NOTAGS)); + $temp->add(new admin_setting_configtext('denyemailaddresses', get_string('denyemailaddresses', 'admin'), get_string('configdenyemailaddresses', 'admin'), '', PARAM_NOTAGS)); + $temp->add(new admin_setting_configcheckbox('verifychangedemail', get_string('verifychangedemail', 'admin'), get_string('configverifychangedemail', 'admin'), 1)); + + $temp->add(new admin_setting_configtext('recaptchapublickey', get_string('recaptchapublickey', 'admin'), get_string('configrecaptchapublickey', 'admin'), '', PARAM_NOTAGS)); + $temp->add(new admin_setting_configtext('recaptchaprivatekey', get_string('recaptchaprivatekey', 'admin'), get_string('configrecaptchaprivatekey', 'admin'), '', PARAM_NOTAGS)); + $ADMIN->add('authsettings', $temp); + + + if ($auths = get_plugin_list('auth')) { + $authsenabled = get_enabled_auth_plugins(); + $authbyname = array(); + + foreach ($auths as $auth => $authdir) { + $strauthname = get_string('pluginname', "auth_{$auth}"); + $authbyname[$strauthname] = $auth; + } + ksort($authbyname); + + foreach ($authbyname as $strauthname=>$authname) { + if (file_exists($authdir.'/settings.php')) { + // do not show disabled auths in tree, keep only settings link on manage page + $settings = new admin_settingpage('authsetting'.$authname, $strauthname, 'moodle/site:config', !in_array($authname, $authsenabled)); + if ($ADMIN->fulltree) { + include($authdir.'/settings.php'); + } + // TODO: finish implementation of common settings - locking, etc. + $ADMIN->add('authsettings', $settings); + + } else { + $ADMIN->add('authsettings', new admin_externalpage('authsetting'.$authname, $strauthname, "$CFG->wwwroot/$CFG->admin/auth_config.php?auth=$authname", 'moodle/site:config', !in_array($authname, $authsenabled))); + } + } + } + + + // Enrolment plugins + $ADMIN->add('modules', new admin_category('enrolments', get_string('enrolments', 'enrol'))); + $temp = new admin_settingpage('manageenrols', get_string('manageenrols', 'enrol')); + $temp->add(new admin_setting_manageenrols()); + if (empty($CFG->enrol_plugins_enabled)) { + $enabled = array(); + } else { + $enabled = explode(',', $CFG->enrol_plugins_enabled); + } + $enrols = get_plugin_list('enrol'); + $ADMIN->add('enrolments', $temp); + foreach($enrols as $enrol=>$enrolpath) { + if (!file_exists("$enrolpath/settings.php")) { + continue; + } + + $settings = new admin_settingpage('enrolsettings'.$enrol, get_string('pluginname', 'enrol_'.$enrol), 'moodle/site:config', !in_array($enrol, $enabled)); + // settings.php may create a subcategory or unset the settings completely + include("$enrolpath/settings.php"); + if ($settings) { + $ADMIN->add('enrolments', $settings); + } + + } + unset($enabled); + unset($enrols); + /// Editor plugins $ADMIN->add('modules', new admin_category('editorsettings', get_string('editors', 'editor'))); @@ -63,7 +141,7 @@ if (file_exists($CFG->dirroot . '/lib/editor/'.$editor.'/settings.php')) { $editor_setting = new admin_externalpage('editorsettings'.$editor, $editorstr, $url.'&action=edit&editor='.$editor); $ADMIN->add('editorsettings', $editor_setting); - } + } } /// License types $ADMIN->add('modules', new admin_category('licensesettings', get_string('license'))); @@ -284,7 +362,7 @@ $temp->add(new admin_setting_heading('webservicesaredisabled', '', get_string('disabledwarning', 'webservice'))); } $ADMIN->add('webservicesettings', $temp); - + if ($hassiteconfig || has_capability('moodle/question:config', $systemcontext)) { // Question type settings. diff --git a/admin/settings/security.php b/admin/settings/security.php index ca4102c4e1fda..4d0d6aae2e166 100644 --- a/admin/settings/security.php +++ b/admin/settings/security.php @@ -67,6 +67,7 @@ $temp->add(new admin_setting_configtext('minpasswordupper', get_string('minpasswordupper', 'admin'), get_string('configminpasswordupper', 'admin'), 1, PARAM_INT)); $temp->add(new admin_setting_configtext('minpasswordnonalphanum', get_string('minpasswordnonalphanum', 'admin'), get_string('configminpasswordnonalphanum', 'admin'), 1, PARAM_INT)); $temp->add(new admin_setting_configtext('maxconsecutiveidentchars', get_string('maxconsecutiveidentchars', 'admin'), get_string('configmaxconsecutiveidentchars', 'admin'), 0, PARAM_INT)); + $temp->add(new admin_setting_configcheckbox('groupenrolmentkeypolicy', get_string('groupenrolmentkeypolicy', 'admin'), get_string('groupenrolmentkeypolicy_desc', 'admin'), 1)); $temp->add(new admin_setting_configcheckbox('disableuserimages', get_string('disableuserimages', 'admin'), get_string('configdisableuserimages', 'admin'), 0)); $temp->add(new admin_setting_configcheckbox('emailchangeconfirmation', get_string('emailchangeconfirmation', 'admin'), get_string('configemailchangeconfirmation', 'admin'), 1)); $ADMIN->add('security', $temp); diff --git a/admin/settings/users.php b/admin/settings/users.php index 36a1ecba2c780..cade4eee3a8b7 100644 --- a/admin/settings/users.php +++ b/admin/settings/users.php @@ -2,7 +2,6 @@ // This file defines settingpages and externalpages under the "users" category -$ADMIN->add('users', new admin_category('authsettings', get_string('authentication','admin'))); $ADMIN->add('users', new admin_category('accounts', get_string('accounts', 'admin'))); $ADMIN->add('users', new admin_category('roles', get_string('permissions', 'role'))); @@ -17,54 +16,6 @@ or has_capability('moodle/cohort:view', $systemcontext)) { // speedup for non-admins, add all caps used on this page - $temp = new admin_settingpage('manageauths', get_string('authsettings', 'admin')); - $temp->add(new admin_setting_manageauths()); - $temp->add(new admin_setting_heading('manageauthscommonheading', get_string('commonsettings', 'admin'), '')); - $temp->add(new admin_setting_special_registerauth()); - $temp->add(new admin_setting_configselect('guestloginbutton', get_string('guestloginbutton', 'auth'), - get_string('showguestlogin', 'auth'), '1', array('0'=>get_string('hide'), '1'=>get_string('show')))); - $temp->add(new admin_setting_configtext('alternateloginurl', get_string('alternateloginurl', 'auth'), - get_string('alternatelogin', 'auth', htmlspecialchars(get_login_url())), '')); - $temp->add(new admin_setting_configtext('forgottenpasswordurl', get_string('forgottenpasswordurl', 'auth'), - get_string('forgottenpassword', 'auth'), '')); - $temp->add(new admin_setting_confightmleditor('auth_instructions', get_string('instructions', 'auth'), - get_string('authinstructions', 'auth'), '')); - $temp->add(new admin_setting_configtext('allowemailaddresses', get_string('allowemailaddresses', 'admin'), get_string('configallowemailaddresses', 'admin'), '', PARAM_NOTAGS)); - $temp->add(new admin_setting_configtext('denyemailaddresses', get_string('denyemailaddresses', 'admin'), get_string('configdenyemailaddresses', 'admin'), '', PARAM_NOTAGS)); - $temp->add(new admin_setting_configcheckbox('verifychangedemail', get_string('verifychangedemail', 'admin'), get_string('configverifychangedemail', 'admin'), 1)); - - $temp->add(new admin_setting_configtext('recaptchapublickey', get_string('recaptchapublickey', 'admin'), get_string('configrecaptchapublickey', 'admin'), '', PARAM_NOTAGS)); - $temp->add(new admin_setting_configtext('recaptchaprivatekey', get_string('recaptchaprivatekey', 'admin'), get_string('configrecaptchaprivatekey', 'admin'), '', PARAM_NOTAGS)); - $ADMIN->add('authsettings', $temp); - - - if ($auths = get_plugin_list('auth')) { - $authsenabled = get_enabled_auth_plugins(); - $authbyname = array(); - - foreach ($auths as $auth => $authdir) { - $strauthname = get_string('pluginname', "auth_{$auth}"); - $authbyname[$strauthname] = $auth; - } - ksort($authbyname); - - foreach ($authbyname as $strauthname=>$authname) { - if (file_exists($authdir.'/settings.php')) { - // do not show disabled auths in tree, keep only settings link on manage page - $settings = new admin_settingpage('authsetting'.$authname, $strauthname, 'moodle/site:config', !in_array($authname, $authsenabled)); - if ($ADMIN->fulltree) { - include($authdir.'/settings.php'); - } - // TODO: finish implementation of common settings - locking, etc. - $ADMIN->add('authsettings', $settings); - - } else { - $ADMIN->add('authsettings', new admin_externalpage('authsetting'.$authname, $strauthname, "$CFG->wwwroot/$CFG->admin/auth_config.php?auth=$authname", 'moodle/site:config', !in_array($authname, $authsenabled))); - } - } - } - - if (empty($CFG->loginhttps)) { $securewwwroot = $CFG->wwwroot; } else { @@ -94,7 +45,7 @@ $studentroles = array(); $teacherroles = array(); $creatornewroles = array(); - + foreach (get_all_roles() as $role) { $rolename = strip_tags(format_string($role->name)) . ' ('. $role->shortname . ')'; $allroles[$role->id] = $rolename; @@ -135,7 +86,7 @@ $defaultstudentid = key($studentroles); reset($teacherroles); $defaultteacherid = key($teacherroles); - + if ($userroles) { reset($userroles); $defaultuserid = key($userroles); @@ -155,19 +106,12 @@ $temp->add(new admin_setting_configcheckbox('nodefaultuserrolelists', get_string('nodefaultuserrolelists', 'admin'), get_string('confignodefaultuserrolelists', 'admin'), 0)); if (!during_initial_install()) { - $temp->add(new admin_setting_configselect('defaultcourseroleid', get_string('defaultcourseroleid', 'admin'), - get_string('configdefaultcourseroleid', 'admin'), $defaultstudentid, $allroles)); $temp->add(new admin_setting_configselect('creatornewroleid', get_string('creatornewroleid', 'admin'), get_string('configcreatornewroleid', 'admin'), $defaultteacherid, $creatornewroles)); } $temp->add(new admin_setting_configcheckbox('autologinguests', get_string('autologinguests', 'admin'), get_string('configautologinguests', 'admin'), 0)); - if (!during_initial_install()) { - $temp->add(new admin_setting_configmultiselect('nonmetacoursesyncroleids', get_string('nonmetacoursesyncroleids', 'admin'), - get_string('confignonmetacoursesyncroleids', 'admin'), array(), $allroles)); - } - $temp->add(new admin_setting_configmultiselect('hiddenuserfields', get_string('hiddenuserfields', 'admin'), get_string('confighiddenuserfields', 'admin'), array(), array('description' => get_string('description'), diff --git a/admin/uploaduser.php b/admin/uploaduser.php index c58c998b0612e..bc2d1d55d7b18 100755 --- a/admin/uploaduser.php +++ b/admin/uploaduser.php @@ -162,26 +162,21 @@ $weakpasswords = 0; // caches - $ccache = array(); // course cache - do not fetch all courses here, we will not probably use them all anyway! - $rolecache = array(); // roles lookup cache + $ccache = array(); // course cache - do not fetch all courses here, we will not probably use them all anyway! + $rolecache = uu_allowed_roles_cache(); // roles lookup cache + $manualcacche = array(); // cache of used manual enrol plugins in each course $allowedauths = uu_allowed_auths(); $allowedauths = array_keys($allowedauths); $availableauths = get_plugin_list('auth'); $availableauths = array_keys($availableauths); - $allowedroles = uu_allowed_roles(true); - foreach ($allowedroles as $rid=>$rname) { - $rolecache[$rid] = new object(); - $rolecache[$rid]->id = $rid; - $rolecache[$rid]->name = $rname; - if (!is_numeric($rname)) { // only non-numeric shornames are supported!!! - $rolecache[$rname] = new object(); - $rolecache[$rname]->id = $rid; - $rolecache[$rname]->name = $rname; - } + // we use only manual enrol plugin here, if it is disabled no enrol is done + if (enrol_is_enabled('manual')) { + $manual = enrol_get_plugin('manual'); + } else { + $manual = NULL; } - unset($allowedroles); // clear bulk selection if ($bulk) { @@ -210,7 +205,7 @@ // add fields to user object foreach ($line as $key => $value) { if ($value !== '') { - $key = $columns[$key]; + $key = $columns[$key]; // password is special field if ($key == 'password') { if ($value !== '') { @@ -365,16 +360,11 @@ $renameerrors++; continue; } - if ($DB->set_field('user', 'username', $user->username, array('id'=>$olduser->id))) { - $upt->track('username', '', 'normal', false); // clear previous - $upt->track('username', $oldusername.'-->'.$user->username, 'info'); - $upt->track('status', $struserrenamed); - $renames++; - } else { - $upt->track('status', $strusernotrenamedexists, 'error'); - $renameerrors++; - continue; - } + $DB->set_field('user', 'username', $user->username, array('id'=>$olduser->id)); + $upt->track('username', '', 'normal', false); // clear previous + $upt->track('username', $oldusername.'-->'.$user->username, 'info'); + $upt->track('status', $struserrenamed); + $renames++; } else { $upt->track('status', $strusernotrenamedmissing, 'error'); $renameerrors++; @@ -501,14 +491,9 @@ $upt->track('auth', $struserauthunsupported, 'warning'); } - if ($DB->update_record('user', $existinguser)) { - $upt->track('status', $struserupdated); - $usersupdated++; - } else { - $upt->track('status', $strusernotupdated, 'error'); - $userserrors++; - continue; - } + $DB->update_record('user', $existinguser); + $upt->track('status', $struserupdated); + $usersupdated++; // save custom profile fields data from csv file profile_save_data($existinguser); } @@ -555,26 +540,21 @@ } } - if ($user->id = $DB->insert_record('user', $user)) { - $info = ': ' . $user->username .' (ID = ' . $user->id . ')'; - $upt->track('status', $struseradded); - $upt->track('id', $user->id, 'normal', false); - $usersnew++; - if ($createpasswords and empty($user->password)) { - // passwords will be created and sent out on cron - set_user_preference('create_password', 1, $user->id); - set_user_preference('auth_forcepasswordchange', 1, $user->id); - $upt->track('password', get_string('new')); - } - if ($forcechangepassword) { - set_user_preference('auth_forcepasswordchange', 1, $user->id); - } - } else { - // Record not added -- possibly some other error - $upt->track('status', $strusernotaddederror, 'error'); - $userserrors++; - continue; + $user->id = $DB->insert_record('user', $user); + $info = ': ' . $user->username .' (ID = ' . $user->id . ')'; + $upt->track('status', $struseradded); + $upt->track('id', $user->id, 'normal', false); + $usersnew++; + if ($createpasswords and empty($user->password)) { + // passwords will be created and sent out on cron + set_user_preference('create_password', 1, $user->id); + set_user_preference('auth_forcepasswordchange', 1, $user->id); + $upt->track('password', get_string('new')); } + if ($forcechangepassword) { + set_user_preference('auth_forcepasswordchange', 1, $user->id); + } + // save custom profile fields data profile_save_data($user); @@ -595,9 +575,12 @@ } $i = substr($column, 6); + if (empty($user->{'course'.$i})) { + continue; + } $shortname = $user->{'course'.$i}; if (!array_key_exists($shortname, $ccache)) { - if (!$course = $DB->get_record('course', array('shortname'=>$shortname), 'id, shortname, defaultrole')) { + if (!$course = $DB->get_record('course', array('shortname'=>$shortname), 'id, shortname')) { $upt->track('enrolments', get_string('unknowncourse', 'error', $shortname), 'error'); continue; } @@ -606,62 +589,61 @@ } $courseid = $ccache[$shortname]->id; $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid); - - // find role - $rid = false; - if (!empty($user->{'role'.$i})) { - $addrole = $user->{'role'.$i}; - if (array_key_exists($addrole, $rolecache)) { - $rid = $rolecache[$addrole]->id; + if (!isset($manualcache[$courseid])) { + if ($instances = enrol_get_instances($courseid, false)) { + $manualcache[$courseid] = reset($instances); } else { - $upt->track('enrolments', get_string('unknownrole', 'error', $addrole), 'error'); - continue; + $manualcache[$courseid] = false; } + } - } else if (!empty($user->{'type'.$i})) { - // if no role, then find "old" enrolment type - $addtype = $user->{'type'.$i}; - if ($addtype < 1 or $addtype > 3) { - $upt->track('enrolments', $strerror.': typeN = 1|2|3', 'error'); - continue; - } else if ($addtype == 1 and empty($formdata->uulegacy1)) { - if (empty($ccache[$shortname]->defaultrole)) { - $rid = $CFG->defaultcourseroleid; + if ($manual and $manualcache[$courseid]) { + + // find role + $rid = false; + if (!empty($user->{'role'.$i})) { + $addrole = $user->{'role'.$i}; + if (array_key_exists($addrole, $rolecache)) { + $rid = $rolecache[$addrole]->id; } else { - $rid = $ccache[$shortname]->defaultrole; + $upt->track('enrolments', get_string('unknownrole', 'error', $addrole), 'error'); + continue; } - } else { - $rid = $formdata->{'uulegacy'.$addtype}; - } - } else { - // no role specified, use the default - if (empty($ccache[$shortname]->defaultrole)) { - $rid = $CFG->defaultcourseroleid; + } else if (!empty($user->{'type'.$i})) { + // if no role, then find "old" enrolment type + $addtype = $user->{'type'.$i}; + if ($addtype < 1 or $addtype > 3) { + $upt->track('enrolments', $strerror.': typeN = 1|2|3', 'error'); + continue; + } else if (empty($formdata->{'uulegacy'.$addtype})) { + continue; + } else { + $rid = $formdata->{'uulegacy'.$addtype}; + } } else { - $rid = $ccache[$shortname]->defaultrole; + // no role specified, use the default from manual enrol plugin + $rid = $manualcache[$courseid]->roleid; } - } - // find duration - $timestart = 0; - $timeend = 0; - if (!empty($user->{'enrolperiod'.$i})) { - $duration = (int)$user->{'enrolperiod'.$i} * 86400; // convert days to seconds - if ($duration > 0) { // sanity check - $timestart = time(); - $timeend = $timestart + $duration; - } - } + if ($rid) { + // find duration + $timestart = 0; + $timeend = 0; + if (!empty($user->{'enrolperiod'.$i})) { + $duration = (int)$user->{'enrolperiod'.$i} * 86400; // convert days to seconds + if ($duration > 0) { // sanity check + $timestart = time(); + $timeend = $timestart + $duration; + } + } - if ($rid) { - $a = new object(); - $a->course = $shortname; - $a->role = $rolecache[$rid]->name; - if (role_assign($rid, $user->id, 0, $coursecontext->id, $timestart, $timeend)) { - $upt->track('enrolments', get_string('enrolledincourserole', '', $a)); - } else { - $upt->track('enrolments', get_string('enrolledincoursenotrole', '', $a), 'error'); + $manual->enrol_user($manualcache[$courseid], $user->id, $rid, $timestart, $timeend, true); + + $a = new object(); + $a->course = $shortname; + $a->role = $rolecache[$rid]->name; + $upt->track('enrolments', get_string('enrolledincourserole', 'enrol_manual', $a)); } } @@ -708,6 +690,8 @@ try { if (groups_add_member($gid, $user->id)) { $upt->track('enrolments', get_string('addedtogroup', '', $gname)); + } else { + $upt->track('enrolments', get_string('addedtogroupnot', '', $gname), 'error'); } } catch (moodle_exception $e) { $upt->track('enrolments', get_string('addedtogroupnot', '', $gname), 'error'); @@ -971,7 +955,7 @@ function init() { echo '