|
@ -62,11 +62,6 @@ class enrol_apply_plugin extends enrol_plugin { |
|
|
if ($data = $form->get_data()) { |
|
|
if ($data = $form->get_data()) { |
|
|
// Only process when form submission is for this instance (multi instance support). |
|
|
// Only process when form submission is for this instance (multi instance support). |
|
|
if ($data->instance == $instance->id) { |
|
|
if ($data->instance == $instance->id) { |
|
|
$userInfo = $data; |
|
|
|
|
|
$applydescription = $userInfo->applydescription; |
|
|
|
|
|
unset($userInfo->applydescription); |
|
|
|
|
|
$userInfo->id = $USER->id; |
|
|
|
|
|
|
|
|
|
|
|
$timestart = 0; |
|
|
$timestart = 0; |
|
|
$timeend = 0; |
|
|
$timeend = 0; |
|
|
$roleid = $instance->roleid; |
|
|
$roleid = $instance->roleid; |
|
@ -75,10 +70,10 @@ class enrol_apply_plugin extends enrol_plugin { |
|
|
$userenrolment = $DB->get_record('user_enrolments', array('userid' => $USER->id, 'enrolid' => $instance->id), 'id', MUST_EXIST); |
|
|
$userenrolment = $DB->get_record('user_enrolments', array('userid' => $USER->id, 'enrolid' => $instance->id), 'id', MUST_EXIST); |
|
|
$applicationinfo = new stdClass(); |
|
|
$applicationinfo = new stdClass(); |
|
|
$applicationinfo->userenrolmentid = $userenrolment->id; |
|
|
$applicationinfo->userenrolmentid = $userenrolment->id; |
|
|
$applicationinfo->comment = $applydescription; |
|
|
$applicationinfo->comment = $data->applydescription; |
|
|
$DB->insert_record('enrol_apply_applicationinfo', $applicationinfo, false); |
|
|
$DB->insert_record('enrol_apply_applicationinfo', $applicationinfo, false); |
|
|
$this->sendConfirmMailToTeachers($instance, $data, $applydescription); |
|
|
|
|
|
$this->sendConfirmMailToManagers($instance, $data, $applydescription); |
|
|
$this->send_application_notification($instance, $USER->id, $data); |
|
|
|
|
|
|
|
|
redirect("$CFG->wwwroot/course/view.php?id=$instance->courseid"); |
|
|
redirect("$CFG->wwwroot/course/view.php?id=$instance->courseid"); |
|
|
} |
|
|
} |
|
@ -284,89 +279,56 @@ class enrol_apply_plugin extends enrol_plugin { |
|
|
email_to_user($user, $contact, $subject, html_to_text($body), $body); |
|
|
email_to_user($user, $contact, $subject, html_to_text($body), $body); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function sendConfirmMailToTeachers($instance,$info,$applydescription){ |
|
|
function send_application_notification($instance, $userid, $data) { |
|
|
global $DB; |
|
|
global $PAGE; |
|
|
global $CFG; |
|
|
|
|
|
global $USER; |
|
|
|
|
|
|
|
|
|
|
|
$courseid = $instance->courseid; |
|
|
$renderer = $PAGE->get_renderer('enrol_apply'); |
|
|
$instanceid = $instance->id; |
|
|
|
|
|
|
|
|
|
|
|
if($instance->customint3 == 1){ |
|
|
$course = get_course($instance->courseid); |
|
|
$course = get_course($courseid); |
|
|
$user = core_user::get_user($userid); |
|
|
$context = context_course::instance($courseid, MUST_EXIST); |
|
|
$contact = core_user::get_support_user(); |
|
|
$teacherType = $DB->get_record('role',array("shortname"=>"editingteacher")); |
|
|
|
|
|
$teachers = $DB->get_records('role_assignments', array('contextid'=>$context->id,'roleid'=>$teacherType->id)); |
|
|
|
|
|
|
|
|
|
|
|
if (!$instance->customint1) { |
|
|
// Include standard user profile fields? |
|
|
$info = null; |
|
|
$standarduserfields = null; |
|
|
|
|
|
if ($instance->customint1) { |
|
|
|
|
|
$standarduserfields = $data; |
|
|
|
|
|
unset($standarduserfields->applydescription); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$extra = null; |
|
|
// Include extra user profile fields? |
|
|
if($instance->customint2){ |
|
|
$extrauserfields = null; |
|
|
|
|
|
if ($instance->customint2) { |
|
|
require_once($CFG->dirroot.'/user/profile/lib.php'); |
|
|
require_once($CFG->dirroot.'/user/profile/lib.php'); |
|
|
$user = $DB->get_record('user',array('id'=>$USER->id)); |
|
|
$user = $DB->get_record('user',array('id' => $user->id)); |
|
|
profile_load_custom_fields($user); |
|
|
profile_load_custom_fields($user); |
|
|
$extra = $user->profile; |
|
|
$extrauserfields = $user->profile; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$manageurl = new moodle_url("/enrol/apply/manage.php", array('id'=>$instanceid)); |
|
|
// Send notification to Teachers? Instance depending. |
|
|
|
|
|
if ($instance->customint3 == 1) { |
|
|
global $PAGE; |
|
|
$context = context_course::instance($instance->courseid); |
|
|
$renderer = $PAGE->get_renderer('enrol_apply'); |
|
|
$editingteacherroles = get_archetype_roles('editingteacher'); |
|
|
$body = $renderer->application_notification_mail_body($course, $USER, $manageurl, $applydescription, $info, $extra); |
|
|
$editingteacherrole = reset($editingteacherroles); |
|
|
|
|
|
$teachers = get_role_users($editingteacherrole->id, $context); |
|
|
$contact = core_user::get_support_user(); |
|
|
|
|
|
|
|
|
|
|
|
foreach($teachers as $teacher){ |
|
|
|
|
|
$editTeacher = $DB->get_record('user',array('id'=>$teacher->userid)); |
|
|
|
|
|
|
|
|
|
|
|
$info = $editTeacher; |
|
|
$manageurl = new moodle_url("/enrol/apply/manage.php", array('id' => $instance->id)); |
|
|
$info->coursename = $course->fullname; |
|
|
$body = $renderer->application_notification_mail_body($course, $user, $manageurl, $data->applydescription, $standarduserfields, $extrauserfields); |
|
|
email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body); |
|
|
foreach ($teachers as $teacher) { |
|
|
} |
|
|
email_to_user($teacher, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function sendConfirmMailToManagers($instance,$info,$applydescription){ |
|
|
// Send notification to managers in system context? |
|
|
global $DB; |
|
|
if (get_config('enrol_apply', 'sendmailtomanager') == 1) { |
|
|
global $CFG; |
|
|
|
|
|
global $USER; |
|
|
|
|
|
|
|
|
|
|
|
$courseid = $instance->courseid; |
|
|
|
|
|
|
|
|
|
|
|
if(get_config('enrol_apply', 'sendmailtomanager') == 1){ |
|
|
|
|
|
$course = get_course($courseid); |
|
|
|
|
|
$context = context_system::instance(); |
|
|
$context = context_system::instance(); |
|
|
$managerType = $DB->get_record('role',array("shortname"=>"manager")); |
|
|
$managerroles = get_archetype_roles('manager'); |
|
|
$managers = $DB->get_records('role_assignments', array('contextid'=>$context->id,'roleid'=>$managerType->id)); |
|
|
$managerrole = reset($editingteacherroles); |
|
|
|
|
|
$managers = get_role_users($managerrole->id, $context); |
|
|
if (!$instance->customint1) { |
|
|
|
|
|
$info = null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$extra = null; |
|
|
|
|
|
if($instance->customint2){ |
|
|
|
|
|
require_once($CFG->dirroot.'/user/profile/lib.php'); |
|
|
|
|
|
$user = $DB->get_record('user',array('id'=>$USER->id)); |
|
|
|
|
|
profile_load_custom_fields($user); |
|
|
|
|
|
$extra = $user->profile; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$manageurl = new moodle_url('/enrol/apply/manage.php'); |
|
|
$manageurl = new moodle_url('/enrol/apply/manage.php'); |
|
|
|
|
|
$body = $renderer->application_notification_mail_body($course, $user, $manageurl, $data->applydescription, $standarduserfields, $extrauserfields); |
|
|
global $PAGE; |
|
|
foreach ($managers as $manager) { |
|
|
$renderer = $PAGE->get_renderer('enrol_apply'); |
|
|
email_to_user($manager, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body); |
|
|
$body = $renderer->application_notification_mail_body($course, $USER, $manageurl, $applydescription, $info, $extra); |
|
|
|
|
|
|
|
|
|
|
|
$contact = core_user::get_support_user(); |
|
|
|
|
|
|
|
|
|
|
|
foreach($managers as $manager){ |
|
|
|
|
|
$userWithManagerRole = $DB->get_record('user',array('id'=>$manager->userid)); |
|
|
|
|
|
|
|
|
|
|
|
$info = $userWithManagerRole; |
|
|
|
|
|
$info->coursename = $course->fullname; |
|
|
|
|
|
email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|