</td>
</tr>
+<tr>
+ <td align="right">enrol_db_disableunenrol:</td>
+ <td>
+ <?php
+ choose_from_menu($yesno, "enrol_db_disableunenrol", $frm->enrol_db_disableunenrol, "");
+ if (isset($err['enrol_db_disableunenrol'])) {
+ formerr($err['enrol_db_disableunenrol']);
+ }
+ ?>
+ </td>
+ <td>
+ <?php print_string('disableunenrol', 'enrol_database' ); ?>
+ </td>
+</tr>
</table>
/// We have some courses left that we might need to unenrol from
/// Note: we only process enrolments that we (ie 'database' plugin) made
- foreach ($existing as $role_assignment) {
- if ($role_assignment->enrol == 'database') {
- //error_log('[ENROL_DB] Removing user from context '.$role_assignment->contextid);
- role_unassign($role_assignment->roleid, $user->id, '', $role_assignment->contextid);
+ /// Do not unenrol anybody if the disableunenrol option is 'yes'
+ if (!$CFG->enrol_db_disableunenrol) {
+ foreach ($existing as $role_assignment) {
+ if ($role_assignment->enrol == 'database') {
+ //error_log('[ENROL_DB] Removing user from context '.$role_assignment->contextid);
+ role_unassign($role_assignment->roleid, $user->id, '', $role_assignment->contextid);
+ }
}
}
} else {
'enrol_db_autocreate', 'enrol_db_category', 'enrol_db_template',
'enrol_db_localrolefield', 'enrol_db_remoterolefield',
'enrol_remotecoursefield', 'enrol_remoteuserfield',
- 'enrol_db_ignorehiddencourse', 'enrol_db_defaultcourseroleid');
+ 'enrol_db_ignorehiddencourse', 'enrol_db_defaultcourseroleid',
+ 'enrol_db_disableunenrol');
foreach ($vars as $var) {
if (!isset($frm->$var)) {
}
set_config('enrol_db_ignorehiddencourse', $config->enrol_db_ignorehiddencourse );
+ if (!isset($config->enrol_db_disableunenrol)) {
+ $config->enrol_db_disableunenrol = '';
+ }
+ set_config('enrol_db_disableunenrol', $config->enrol_db_disableunenrol );
+
return true;
}
return $newcourseid;
}
+/**
+ * Test the database connection
+ * @return true if it works
+ */
+function test() {
+ return true;
+}
+
/// DB Connect
/// NOTE: You MUST remember to disconnect
/// when you stop using it -- as this call will
$string['dbtable'] = 'Database table';
$string['defaultcourseroleid'] = 'The role that will be assigned by default if no other role is specified.';
$string['description'] = 'You can use a external database (of nearly any kind) to control your enrolments. It is assumed your external database contains a field containing a course ID, and a field containing a user ID. These are compared against fields that you choose in the local course and user tables.';
+$string['disableunenrol'] = 'If set to yes users previously enrolled by the external database plugin will not be unenrolled by the same plugin regardless of the database contents.';
$string['enrolname'] = 'External Database';
$string['enrol_database_autocreation_settings'] = 'Auto-creation of new courses';
$string['general_options'] = 'General Options';