diff --git a/lib.php b/lib.php index 854875c..d82bb91 100644 --- a/lib.php +++ b/lib.php @@ -330,51 +330,30 @@ function sendConfirmMailToTeachers($instance,$info,$applydescription){ $context = context_course::instance($courseid, MUST_EXIST); $teacherType = $DB->get_record('role',array("shortname"=>"editingteacher")); $teachers = $DB->get_records('role_assignments', array('contextid'=>$context->id,'roleid'=>$teacherType->id)); + + 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", array('id'=>$instanceid)); + + global $PAGE; + $renderer = $PAGE->get_renderer('enrol_apply'); + $body = $renderer->application_notification_mail_body($course, $USER, $manageurl, $applydescription, $info, $extra); + + $contact = core_user::get_support_user(); + foreach($teachers as $teacher){ $editTeacher = $DB->get_record('user',array('id'=>$teacher->userid)); - $body = '
'. get_string('coursename', 'enrol_apply') .': '.format_string($course->fullname).'
'; - $body .= ''. get_string('applyuser', 'enrol_apply') .': '.$USER->firstname.' '.$USER->lastname.'
'; - $body .= ''. get_string('comment', 'enrol_apply') .': '.$applydescription.'
'; - - if($instance->customint1){ - $body .= ''. get_string('user_profile', 'enrol_apply').'
'; - $body .= ''. get_string('firstname') .': '.$info->firstname.'
'; - $body .= ''. get_string('lastname') .': '.$info->lastname.'
'; - $body .= ''. get_string('email') .': '.$info->email.'
'; - $body .= ''. get_string('city') .': '.$info->city.'
'; - $body .= ''. get_string('country') .': '.$info->country.'
'; - $body .= ''. get_string('preferredlanguage') .': '.$info->lang.'
'; - $body .= ''. get_string('description') .': '.$info->description_editor['text'].'
'; - - $body .= ''. get_string('firstnamephonetic') .': '.$info->firstnamephonetic.'
'; - $body .= ''. get_string('lastnamephonetic') .': '.$info->lastnamephonetic.'
'; - $body .= ''. get_string('middlename') .': '.$info->middlename.'
'; - $body .= ''. get_string('alternatename') .': '.$info->alternatename.'
'; - $body .= ''. get_string('url') .': '.$info->url.'
'; - $body .= ''. get_string('icqnumber') .': '.$info->icq.'
'; - $body .= ''. get_string('skypeid') .': '.$info->skype.'
'; - $body .= ''. get_string('aimid') .': '.$info->aim.'
'; - $body .= ''. get_string('yahooid') .': '.$info->yahoo.'
'; - $body .= ''. get_string('msnid') .': '.$info->msn.'
'; - $body .= ''. get_string('idnumber') .': '.$info->idnumber.'
'; - $body .= ''. get_string('institution') .': '.$info->institution.'
'; - $body .= ''. get_string('department') .': '.$info->department.'
'; - $body .= ''. get_string('phone') .': '.$info->phone1.'
'; - $body .= ''. get_string('phone2') .': '.$info->phone2.'
'; - $body .= ''. get_string('address') .': '.$info->address.'
'; - } - - 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); - foreach ($user->profile as $key => $value) { - $body .= ''. $key .': '.$value.'
'; - } - } - $body .= ''. html_writer::link(new moodle_url("/enrol/apply/manage.php", array('id'=>$instanceid)), get_string('applymanage', 'enrol_apply')).'
'; - $contact = core_user::get_support_user(); $info = $editTeacher; $info->coursename = $course->fullname; email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body); @@ -394,50 +373,30 @@ function sendConfirmMailToManagers($instance,$info,$applydescription){ $context = context_system::instance(); $managerType = $DB->get_record('role',array("shortname"=>"manager")); $managers = $DB->get_records('role_assignments', array('contextid'=>$context->id,'roleid'=>$managerType->id)); + + 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'); + + global $PAGE; + $renderer = $PAGE->get_renderer('enrol_apply'); + $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)); - $body = ''. get_string('coursename', 'enrol_apply') .': '.format_string($course->fullname).'
'; - $body .= ''. get_string('applyuser', 'enrol_apply') .': '.$USER->firstname.' '.$USER->lastname.'
'; - $body .= ''. get_string('comment', 'enrol_apply') .': '.$applydescription.'
'; - if($instance->customint1){ - $body .= ''. get_string('user_profile', 'enrol_apply').'
'; - $body .= ''. get_string('firstname') .': '.$info->firstname.'
'; - $body .= ''. get_string('lastname') .': '.$info->lastname.'
'; - $body .= ''. get_string('email') .': '.$info->email.'
'; - $body .= ''. get_string('city') .': '.$info->city.'
'; - $body .= ''. get_string('country') .': '.$info->country.'
'; - $body .= ''. get_string('preferredlanguage') .': '.$info->lang.'
'; - $body .= ''. get_string('description') .': '.$info->description_editor['text'].'
'; - - $body .= ''. get_string('firstnamephonetic') .': '.$info->firstnamephonetic.'
'; - $body .= ''. get_string('lastnamephonetic') .': '.$info->lastnamephonetic.'
'; - $body .= ''. get_string('middlename') .': '.$info->middlename.'
'; - $body .= ''. get_string('alternatename') .': '.$info->alternatename.'
'; - $body .= ''. get_string('url') .': '.$info->url.'
'; - $body .= ''. get_string('icqnumber') .': '.$info->icq.'
'; - $body .= ''. get_string('skypeid') .': '.$info->skype.'
'; - $body .= ''. get_string('aimid') .': '.$info->aim.'
'; - $body .= ''. get_string('yahooid') .': '.$info->yahoo.'
'; - $body .= ''. get_string('msnid') .': '.$info->msn.'
'; - $body .= ''. get_string('idnumber') .': '.$info->idnumber.'
'; - $body .= ''. get_string('institution') .': '.$info->institution.'
'; - $body .= ''. get_string('department') .': '.$info->department.'
'; - $body .= ''. get_string('phone') .': '.$info->phone1.'
'; - $body .= ''. get_string('phone2') .': '.$info->phone2.'
'; - $body .= ''. get_string('address') .': '.$info->address.'
'; - } - - 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); - foreach ($user->profile as $key => $value) { - $body .= ''. $key .': '.$value.'
'; - } - } - $body .= ''. html_writer::link(new moodle_url('/enrol/apply/manage.php'), get_string('applymanage', 'enrol_apply')).'
'; - $contact = core_user::get_support_user(); $info = $userWithManagerRole; $info->coursename = $course->fullname; email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body); diff --git a/renderer.php b/renderer.php index 53e491e..902902c 100644 --- a/renderer.php +++ b/renderer.php @@ -71,4 +71,47 @@ class enrol_apply_renderer extends plugin_renderer_base { $table->out(50, true); } + + public function application_notification_mail_body($course, $user, $manageurl, $applydescription, $info = null, $extra = null) { + $body = ''. get_string('coursename', 'enrol_apply') .': '.format_string($course->fullname).'
'; + $body .= ''. get_string('applyuser', 'enrol_apply') .': '.$user->firstname.' '.$user->lastname.'
'; + $body .= ''. get_string('comment', 'enrol_apply') .': '.$applydescription.'
'; + if($info){ + $body .= ''. get_string('user_profile', 'enrol_apply').'
'; + $body .= ''. get_string('firstname') .': '.$info->firstname.'
'; + $body .= ''. get_string('lastname') .': '.$info->lastname.'
'; + $body .= ''. get_string('email') .': '.$info->email.'
'; + $body .= ''. get_string('city') .': '.$info->city.'
'; + $body .= ''. get_string('country') .': '.$info->country.'
'; + $body .= ''. get_string('preferredlanguage') .': '.$info->lang.'
'; + $body .= ''. get_string('description') .': '.$info->description_editor['text'].'
'; + + $body .= ''. get_string('firstnamephonetic') .': '.$info->firstnamephonetic.'
'; + $body .= ''. get_string('lastnamephonetic') .': '.$info->lastnamephonetic.'
'; + $body .= ''. get_string('middlename') .': '.$info->middlename.'
'; + $body .= ''. get_string('alternatename') .': '.$info->alternatename.'
'; + $body .= ''. get_string('url') .': '.$info->url.'
'; + $body .= ''. get_string('icqnumber') .': '.$info->icq.'
'; + $body .= ''. get_string('skypeid') .': '.$info->skype.'
'; + $body .= ''. get_string('aimid') .': '.$info->aim.'
'; + $body .= ''. get_string('yahooid') .': '.$info->yahoo.'
'; + $body .= ''. get_string('msnid') .': '.$info->msn.'
'; + $body .= ''. get_string('idnumber') .': '.$info->idnumber.'
'; + $body .= ''. get_string('institution') .': '.$info->institution.'
'; + $body .= ''. get_string('department') .': '.$info->department.'
'; + $body .= ''. get_string('phone') .': '.$info->phone1.'
'; + $body .= ''. get_string('phone2') .': '.$info->phone2.'
'; + $body .= ''. get_string('address') .': '.$info->address.'
'; + } + + if($extra){ + foreach ($extra as $key => $value) { + $body .= ''. $key .': '.$value.'
'; + } + } + + $body .= ''. html_writer::link($manageurl, get_string('applymanage', 'enrol_apply')).'
'; + + return $body; + } } \ No newline at end of file