diff --git a/lang/en/enrol_ilbead.php b/lang/en/enrol_ilbead.php
index 60145ed..9ee993f 100644
--- a/lang/en/enrol_ilbead.php
+++ b/lang/en/enrol_ilbead.php
@@ -122,3 +122,7 @@ $string['timeend'] = 'Expected time end';
$string['maxongoingmessage'] = 'You are already enrolled in {$a} ILB/EAD courses, New enrollments will only be accepted after the completion of at least one of them.';
$string['customenrolmessage'] = 'Custom enrol message';
$string['customenrolmessage_help'] = 'A custom message may be displayed at enrol form as plain text or Moodle-auto format, including HTML tags and multi-lang tags.';
+$string['samecoursealert'] = 'Wrong classroom!';
+$string['samecoursemessage'] = 'You are already enrolled in this course, but in another class!
+Your correct classroom is {$a}.';
+$string['alreadyenroled'] = 'You are already enrolled in this but cannot access them.';
diff --git a/lang/pt_br/enrol_ilbead.php b/lang/pt_br/enrol_ilbead.php
index ec6a103..06bdbb8 100644
--- a/lang/pt_br/enrol_ilbead.php
+++ b/lang/pt_br/enrol_ilbead.php
@@ -122,3 +122,7 @@ $string['timeend'] = 'Data prevista de término';
$string['maxongoingmessage'] = 'Você já está matriculado em {$a} curso(s) sem tutoria, Novas matrículas somente serão aceitas após a conclusão de pelo menos um deles.';
$string['customenrolmessage'] = 'Mensagem personalizada de matrícula';
$string['customenrolmessage_help'] = 'Uma mensagem personalizada que pode ser exibida no formulário de inscrição como um texto plano ou no padrão de autoformatação Moodle, incluindo tags HTML e multi-linguagem.';
+$string['samecoursealert'] = 'Turma errada!';
+$string['samecoursemessage'] = 'Você já está matriculado neste curso, mas em outra turma!
+Sua turma correta é {$a}.';
+$string['alreadyenroled'] = 'Você já está inscrito neste curso mas não pode acessá-lo.';
diff --git a/lib.php b/lib.php
index d86b945..d75ec2b 100644
--- a/lib.php
+++ b/lib.php
@@ -201,9 +201,10 @@ class enrol_ilbead_plugin extends enrol_plugin {
// Can not enrol guest!!
return null;
}
+
if ($DB->record_exists('user_enrolments', array('userid'=>$USER->id, 'enrolid'=>$instance->id))) {
- //TODO: maybe we should tell them they are already enrolled, but can not access the course
- return null;
+ $error = get_string('alreadyenroled', 'enrol_ilbead');
+ return $OUTPUT->box($error).$OUTPUT->continue_button("$CFG->wwwroot/index.php");
}
if ($instance->enrolstartdate != 0 and $instance->enrolstartdate > time()) {
@@ -221,8 +222,9 @@ class enrol_ilbead_plugin extends enrol_plugin {
return null;
}
+ $ongoing = $this->get_ongoing($instance);
+
if ($instance->customint7 !== null and $instance->customint7 > 0) {
- $ongoing = $this->get_ongoing($instance);
if (count($ongoing) >= $instance->customint7) {
// Max ongoing EAD courses reached. New enrol not allowed
$error = $OUTPUT->error_text(get_string('maxongoing', 'enrol_ilbead'));
@@ -242,6 +244,22 @@ class enrol_ilbead_plugin extends enrol_plugin {
}
}
+ $course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST);
+ $course_prefix = explode('.', $course->idnumber);
+ $course_prefix = $course_prefix[0];
+
+ foreach ($ongoing as $course) {
+ $ongoing_prefix = explode('.', $course->idnumber);
+ $ongoing_prefix = $ongoing_prefix[0];
+ if ($course_prefix == $ongoing_prefix) {
+ $error = $OUTPUT->error_text(get_string('samecoursealert', 'enrol_ilbead'));
+ $link = ''.$course->fullname.'';
+ $error .= '
'.get_string('samecoursemessage', 'enrol_ilbead', $link).'
'; + $error = $OUTPUT->box($error).$OUTPUT->continue_button("$CFG->wwwroot/index.php"); + return $error; + } + } + if ($instance->customint5) { require_once("$CFG->dirroot/cohort/lib.php"); if (!cohort_is_member($instance->customint5, $USER->id)) {