diff --git a/db/upgrade.php b/db/upgrade.php index e0b32eb..76083b9 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -102,6 +102,14 @@ function xmldb_enrol_apply_upgrade($oldversion) { } } + if ($oldversion < 2018112603) { + $instances = $DB->get_records('enrol', array('enrol' => 'apply')); + foreach ($instances as $instance) { + $instance->customint6 = 1; + $DB->update_record('enrol', $instance, true); + } + } + return true; } \ No newline at end of file diff --git a/edit.php b/edit.php index 290626f..afa2c78 100644 --- a/edit.php +++ b/edit.php @@ -95,6 +95,7 @@ if ($mform->is_cancelled()) { $instance->customint1 = $data->customint1; $instance->customint2 = $data->customint2; $instance->customint3 = $data->customint3; + $instance->customint6 = $data->customint6; $instance->roleid = $data->roleid; $instance->enrolperiod = $data->enrolperiod; $instance->timemodified = time(); @@ -107,6 +108,7 @@ if ($mform->is_cancelled()) { 'customint1' => $data->customint1, 'customint2' => $data->customint2, 'customint3' => $data->customint3, + 'customint6' => $data->customint6, 'customtext1' => $data->customtext1, 'customtext2' => $data->customtext2, 'enrolperiod' => $data->enrolperiod diff --git a/edit_form.php b/edit_form.php index db7efae..6e0cd08 100644 --- a/edit_form.php +++ b/edit_form.php @@ -44,6 +44,12 @@ class enrol_apply_edit_form extends moodleform { // $mform->addHelpButton('status', 'status', 'enrol_apply'); $mform->setDefault('status', $plugin->get_config('status')); + $mform->addElement('select', 'customint6', get_string('newenrols', 'enrol_apply'), array( + 1 => get_string('yes'), + 0 => get_string('no') + )); + $mform->setDefault('newenrols', $plugin->get_config('newenrols')); + if ($instance->id) { $roles = get_default_enrol_roles($context, $instance->roleid); } else { diff --git a/lang/en/enrol_apply.php b/lang/en/enrol_apply.php index ec2c31a..ed28035 100644 --- a/lang/en/enrol_apply.php +++ b/lang/en/enrol_apply.php @@ -78,6 +78,7 @@ $string['btncancel'] = 'Cancel requests'; $string['enrolusers'] = 'Enrol users'; $string['status'] = 'Allow Course enrol confirmation'; +$string['newenrols'] = 'Allow new course enrol confirmation'; $string['confirmenrol'] = 'Manage application'; $string['apply:config'] = 'Configure apply enrol instances'; @@ -104,6 +105,8 @@ $string['maxenrolled_help'] = 'Specifies the maximum number of users that can se $string['maxenrolledreached_left'] = 'Maximum number of users allowed'; $string['maxenrolledreached_right'] = 'has already been reached.'; +$string['cantenrol'] = 'Enrolment is disabled or inactive'; + $string['maxenrolled_tip_1'] = 'out of'; $string['maxenrolled_tip_2'] = 'seats already booked.'; diff --git a/lib.php b/lib.php index 17abb1d..40e8ac2 100644 --- a/lib.php +++ b/lib.php @@ -45,6 +45,17 @@ class enrol_apply_plugin extends enrol_plugin { // Users may tweak the roles later. return false; } + + public function allow_apply(stdClass $instance) { + if ($instance->status != ENROL_INSTANCE_ENABLED) { + return get_string('cantenrol', 'enrol_apply'); + } + if (!$instance->customint6) { + // New enrols not allowed. + return get_string('cantenrol', 'enrol_apply'); + } + return true; + } /** * Prevent to unenrol an user with a pending application * @@ -85,6 +96,12 @@ class enrol_apply_plugin extends enrol_plugin { // Can not enrol guest! return null; } + + $allowapply = $this->allow_apply($instance); + if ($allowapply !== true) { + return '