@ -77,8 +77,8 @@ class enrol_apply_plugin extends enrol_plugin {
$applicationinfo->userenrolmentid = $userenrolment->id;
$applicationinfo->userenrolmentid = $userenrolment->id;
$applicationinfo->comment = $applydescription;
$applicationinfo->comment = $applydescription;
$DB->insert_record('enrol_apply_applicationinfo', $applicationinfo, false);
$DB->insert_record('enrol_apply_applicationinfo', $applicationinfo, false);
sendConfirmMailToTeachers($instance, $data, $applydescription);
$this-> sendConfirmMailToTeachers($instance, $data, $applydescription);
sendConfirmMailToManagers($instance, $data, $applydescription);
$this-> sendConfirmMailToManagers($instance, $data, $applydescription);
// Deprecated fixed by Shiro < gigashiro @ gmail . com >
// Deprecated fixed by Shiro < gigashiro @ gmail . com >
//add_to_log($instance->courseid, 'course', 'enrol', '../enrol/users.php?id='.$instance->courseid, $instance->courseid); //there should be userid somewhere!
//add_to_log($instance->courseid, 'course', 'enrol', '../enrol/users.php?id='.$instance->courseid, $instance->courseid); //there should be userid somewhere!
@ -224,9 +224,9 @@ class enrol_apply_plugin extends enrol_plugin {
$this->update_user_enrol($instance, $userenrolment->userid, ENROL_USER_ACTIVE);
$this->update_user_enrol($instance, $userenrolment->userid, ENROL_USER_ACTIVE);
$info = getRelatedInfo($enrol);
$info = $this-> getRelatedInfo($enrol);
$DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol));
$DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol));
sendConfirmMail($info);
$this-> sendConfirmMail($info);
}
}
}
}
@ -246,8 +246,8 @@ class enrol_apply_plugin extends enrol_plugin {
$this->update_user_enrol($instance, $userenrolment->userid, ENROL_APPLY_USER_WAIT);
$this->update_user_enrol($instance, $userenrolment->userid, ENROL_APPLY_USER_WAIT);
$info = getRelatedInfo($enrol);
$info = $this-> getRelatedInfo($enrol);
sendWaitMail($info);
$this-> sendWaitMail($info);
}
}
}
}
}
}
@ -273,147 +273,147 @@ class enrol_apply_plugin extends enrol_plugin {
continue;
continue;
}
}
$info = getRelatedInfo($enrol);
$info = $this-> getRelatedInfo($enrol);
$this->unenrol_user($instance, $userenrolment->userid);
$this->unenrol_user($instance, $userenrolment->userid);
$DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol));
$DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol));
sendCancelMail($info);
$this-> sendCancelMail($info);
}
}
}
}
}
function sendCancelMail($info){
function sendCancelMail($info){
global $DB;
global $DB;
global $CFG;
global $CFG;
$replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username);
$replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username);
$body = get_config('enrol_apply', 'cancelmailcontent');
$body = get_config('enrol_apply', 'cancelmailcontent');
$body = updateMailContent($body,$replace);
$body = $this-> updateMailContent($body,$replace);
$contact = core_user::get_support_user();
$contact = core_user::get_support_user();
email_to_user($info, $contact, get_config('enrol_apply', 'cancelmailsubject'), html_to_text($body), $body);
email_to_user($info, $contact, get_config('enrol_apply', 'cancelmailsubject'), html_to_text($body), $body);
}
}
function sendConfirmMail($info){
function sendConfirmMail($info){
global $DB;
global $DB;
global $CFG;
global $CFG;
$replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username);
$replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username);
$body = get_config('enrol_apply', 'confirmmailcontent');
$body = get_config('enrol_apply', 'confirmmailcontent');
$body = updateMailContent($body,$replace);
$body = $this-> updateMailContent($body,$replace);
$contact = core_user::get_support_user();
$contact = core_user::get_support_user();
email_to_user($info, $contact, get_config('enrol_apply', 'confirmmailsubject'), html_to_text($body), $body);
email_to_user($info, $contact, get_config('enrol_apply', 'confirmmailsubject'), html_to_text($body), $body);
}
}
function sendWaitMail($info){
function sendWaitMail($info){
global $DB;
global $DB;
global $CFG;
global $CFG;
//global $USER;
//global $USER;
$replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username);
$replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username);
$body = get_config('enrol_apply', 'waitmailcontent');
$body = get_config('enrol_apply', 'waitmailcontent');
$body = updateMailContent($body,$replace);
$body = $this-> updateMailContent($body,$replace);
$contact = get_admin();
$contact = get_admin();
//confirm mail will sent by the admin
//confirm mail will sent by the admin
//$contact = $USER;
//$contact = $USER;
email_to_user($info, $contact, get_config('enrol_apply', 'waitmailsubject'), html_to_text($body), $body);
email_to_user($info, $contact, get_config('enrol_apply', 'waitmailsubject'), html_to_text($body), $body);
}
}
function sendConfirmMailToTeachers($instance,$info,$applydescription){
function sendConfirmMailToTeachers($instance,$info,$applydescription){
global $DB;
global $DB;
global $CFG;
global $CFG;
global $USER;
global $USER;
$courseid = $instance->courseid;
$courseid = $instance->courseid;
$instanceid = $instance->id;
$instanceid = $instance->id;
if($instance->customint3 == 1){
if($instance->customint3 == 1){
$course = get_course($courseid);
$course = get_course($courseid);
$context = context_course::instance($courseid, MUST_EXIST);
$context = context_course::instance($courseid, MUST_EXIST);
$teacherType = $DB->get_record('role',array("shortname"=>"editingteacher"));
$teacherType = $DB->get_record('role',array("shortname"=>"editingteacher"));
$teachers = $DB->get_records('role_assignments', array('contextid'=>$context->id,'roleid'=>$teacherType->id));
$teachers = $DB->get_records('role_assignments', array('contextid'=>$context->id,'roleid'=>$teacherType->id));
if (!$instance->customint1) {
if (!$instance->customint1) {
$info = null;
$info = null;
}
}
$extra = null;
$extra = null;
if($instance->customint2){
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;
$extra = $user->profile;
}
}
$manageurl = new moodle_url("/enrol/apply/manage.php", array('id'=>$instanceid));
$manageurl = new moodle_url("/enrol/apply/manage.php", array('id'=>$instanceid));
global $PAGE;
global $PAGE;
$renderer = $PAGE->get_renderer('enrol_apply');
$renderer = $PAGE->get_renderer('enrol_apply');
$body = $renderer->application_notification_mail_body($course, $USER, $manageurl, $applydescription, $info, $extra);
$body = $renderer->application_notification_mail_body($course, $USER, $manageurl, $applydescription, $info, $extra);
$contact = core_user::get_support_user();
$contact = core_user::get_support_user();
foreach($teachers as $teacher){
foreach($teachers as $teacher){
$editTeacher = $DB->get_record('user',array('id'=>$teacher->userid));
$editTeacher = $DB->get_record('user',array('id'=>$teacher->userid));
$info = $editTeacher;
$info = $editTeacher;
$info->coursename = $course->fullname;
$info->coursename = $course->fullname;
email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body);
email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body);
}
}
}
}
}
}
function sendConfirmMailToManagers($instance,$info,$applydescription){
function sendConfirmMailToManagers($instance,$info,$applydescription){
global $DB;
global $DB;
global $CFG;
global $CFG;
global $USER;
global $USER;
$courseid = $instance->courseid;
$courseid = $instance->courseid;
if(get_config('enrol_apply', 'sendmailtomanager') == 1){
if(get_config('enrol_apply', 'sendmailtomanager') == 1){
$course = get_course($courseid);
$course = get_course($courseid);
$context = context_system::instance();
$context = context_system::instance();
$managerType = $DB->get_record('role',array("shortname"=>"manager"));
$managerType = $DB->get_record('role',array("shortname"=>"manager"));
$managers = $DB->get_records('role_assignments', array('contextid'=>$context->id,'roleid'=>$managerType->id));
$managers = $DB->get_records('role_assignments', array('contextid'=>$context->id,'roleid'=>$managerType->id));
if (!$instance->customint1) {
if (!$instance->customint1) {
$info = null;
$info = null;
}
}
$extra = null;
$extra = null;
if($instance->customint2){
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;
$extra = $user->profile;
}
}
$manageurl = new moodle_url('/enrol/apply/manage.php');
$manageurl = new moodle_url('/enrol/apply/manage.php');
global $PAGE;
global $PAGE;
$renderer = $PAGE->get_renderer('enrol_apply');
$renderer = $PAGE->get_renderer('enrol_apply');
$body = $renderer->application_notification_mail_body($course, $USER, $manageurl, $applydescription, $info, $extra);
$body = $renderer->application_notification_mail_body($course, $USER, $manageurl, $applydescription, $info, $extra);
$contact = core_user::get_support_user();
$contact = core_user::get_support_user();
foreach($managers as $manager){
foreach($managers as $manager){
$userWithManagerRole = $DB->get_record('user',array('id'=>$manager->userid));
$userWithManagerRole = $DB->get_record('user',array('id'=>$manager->userid));
$info = $userWithManagerRole;
$info = $userWithManagerRole;
$info->coursename = $course->fullname;
$info->coursename = $course->fullname;
email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body);
email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body);
}
}
}
}
}
}
function getRelatedInfo($enrolid){
function getRelatedInfo($enrolid){
global $DB;
global $DB;
global $CFG;
global $CFG;
return $DB->get_record_sql('select u.*,c.fullname as coursename from '.$CFG->prefix.'user_enrolments as ue left join '.$CFG->prefix.'user as u on ue.userid=u.id left join '.$CFG->prefix.'enrol as e on ue.enrolid=e.id left
return $DB->get_record_sql('select u.*,c.fullname as coursename from '.$CFG->prefix.'user_enrolments as ue left join '.$CFG->prefix.'user as u on ue.userid=u.id left join '.$CFG->prefix.'enrol as e on ue.enrolid=e.id left
join '.$CFG->prefix.'course as c on e.courseid=c.id where ue.id='.$enrolid);
join '.$CFG->prefix.'course as c on e.courseid=c.id where ue.id='.$enrolid);
}
}
function updateMailContent($content,$replace){
function updateMailContent($content,$replace){
foreach ($replace as $key=>$val) {
foreach ($replace as $key=>$val) {
$content = str_replace("{".$key."}",$val,$content);
$content = str_replace("{".$key."}",$val,$content);
}
return $content;
}
}
return $content;
}
}