Browse Source

Merge pull request #16 from jordif/apply-v.1.3

Improvements on notifications for teachers and managers (by Jordif)
develop_fields
Flotter Totte 10 years ago
parent
commit
5473d3b3aa
  1. 2
      apply.php
  2. 2
      lang/ca/enrol_apply.php
  3. 2
      lang/en/enrol_apply.php
  4. 2
      lang/es/enrol_apply.php
  5. 43
      lib.php
  6. 5
      locallib.php
  7. 2
      manage.php
  8. 4
      settings.php

2
apply.php

@ -61,7 +61,7 @@ echo '</tr>';
foreach ( $enrols as $enrol ) { foreach ( $enrols as $enrol ) {
$picture = get_user_picture($enrol->userid); $picture = get_user_picture($enrol->userid);
echo '<tr><td><input type="checkbox" name="enrolid[]" value="' . $enrol->id . '"></td>'; echo '<tr><td><input type="checkbox" name="enrolid[]" value="' . $enrol->id . '"></td>';
echo '<td>' . $enrol->course . '</td>'; echo '<td>' . format_string($enrol->course) . '</td>';
echo '<td>' . $OUTPUT->render($picture) . '</td>'; echo '<td>' . $OUTPUT->render($picture) . '</td>';
echo '<td>'.$enrol->firstname . ' ' . $enrol->lastname.'</td>'; echo '<td>'.$enrol->firstname . ' ' . $enrol->lastname.'</td>';
echo '<td>' . $enrol->email . '</td>'; echo '<td>' . $enrol->email . '</td>';

2
lang/ca/enrol_apply.php

@ -42,8 +42,10 @@ $string['apply:unenrolapply'] = 'Cancel·lar-se a si mateix del curs'; // Needs
$string['notification'] = '<b>Sol·licitud d\'inscripció enviada correctament</b>. <br/><br/>Rebràs una notificació per correu electrònic un cop estigui confirmada la inscripció.'; $string['notification'] = '<b>Sol·licitud d\'inscripció enviada correctament</b>. <br/><br/>Rebràs una notificació per correu electrònic un cop estigui confirmada la inscripció.';
$string['sendmailtoteacher'] = 'Enviar notificacions per correu als professors'; $string['sendmailtoteacher'] = 'Enviar notificacions per correu als professors';
$string['sendmailtomanager'] = 'Enviar notificacions per correu als administradors';
$string['mailtoteacher_suject'] = 'Nova inscripció al curs!'; $string['mailtoteacher_suject'] = 'Nova inscripció al curs!';
$string['editdescription'] = 'Descripció de l\'àrea de text'; $string['editdescription'] = 'Descripció de l\'àrea de text';
$string['comment'] = 'Comentari';
$string['applymanage'] = 'Gestionar inscripcions'; $string['applymanage'] = 'Gestionar inscripcions';
$string['status_desc'] = 'Allow course access of internally enrolled users.'; $string['status_desc'] = 'Allow course access of internally enrolled users.';

2
lang/en/enrol_apply.php

@ -42,8 +42,10 @@ $string['apply:unenrolapply'] = 'Cancel self from the course';
$string['notification'] = '<b>Enrollment Application successfully sent</b>. <br/><br/>You will be informed by email as soon as your enrollment has been confirmed. If you want to enroll to other courses, please click "course catalogue" in the top menu.'; $string['notification'] = '<b>Enrollment Application successfully sent</b>. <br/><br/>You will be informed by email as soon as your enrollment has been confirmed. If you want to enroll to other courses, please click "course catalogue" in the top menu.';
$string['sendmailtoteacher'] = 'Send email notification to teachers'; $string['sendmailtoteacher'] = 'Send email notification to teachers';
$string['sendmailtomanager'] = 'Send email notification to managers';
$string['mailtoteacher_suject'] = 'New Enrollment request!'; $string['mailtoteacher_suject'] = 'New Enrollment request!';
$string['editdescription'] = 'Textarea description'; $string['editdescription'] = 'Textarea description';
$string['comment'] = 'Comment';
$string['applymanage'] = 'Manage enrolment applications'; $string['applymanage'] = 'Manage enrolment applications';
$string['status_desc'] = 'Allow course access of internally enrolled users.'; $string['status_desc'] = 'Allow course access of internally enrolled users.';

2
lang/es/enrol_apply.php

@ -42,8 +42,10 @@ $string['apply:unenrolapply'] = 'Cancelarse a si mismo del curso'; // Needs more
$string['notification'] = '<b>Solicitud de matriculación enviada correctamente</b>. <br/><br/>Será notificado por correo electrónico en cuanto se confirme su matriculación.'; $string['notification'] = '<b>Solicitud de matriculación enviada correctamente</b>. <br/><br/>Será notificado por correo electrónico en cuanto se confirme su matriculación.';
$string['sendmailtoteacher'] = 'Enviar notificaciones por correo a los profesores'; $string['sendmailtoteacher'] = 'Enviar notificaciones por correo a los profesores';
$string['sendmailtomanager'] = 'Enviar notificaciones por correo a los gestores';
$string['mailtoteacher_suject'] = 'Nueva matrícula!'; $string['mailtoteacher_suject'] = 'Nueva matrícula!';
$string['editdescription'] = 'Descripción del área de texto'; $string['editdescription'] = 'Descripción del área de texto';
$string['comment'] = 'Comentario';
$string['applymanage'] = 'Gestionar matrículas'; $string['applymanage'] = 'Gestionar matrículas';
$string['status_desc'] = 'Allow course access of internally enrolled users.'; // needs to be translated $string['status_desc'] = 'Allow course access of internally enrolled users.'; // needs to be translated

43
lib.php

@ -93,7 +93,8 @@ class enrol_apply_plugin extends enrol_plugin {
} }
$this->enrol_user($instance, $USER->id, $roleid, $timestart, $timeend,1); $this->enrol_user($instance, $USER->id, $roleid, $timestart, $timeend,1);
sendConfirmMailToTeachers($instance->courseid,$data->applydescription); sendConfirmMailToTeachers($instance->courseid, $instance->id, $data->applydescription);
sendConfirmMailToManagers($instance->courseid,$data->applydescription);
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!
redirect("$CFG->wwwroot/course/view.php?id=$instance->courseid"); redirect("$CFG->wwwroot/course/view.php?id=$instance->courseid");
@ -160,7 +161,7 @@ function getAllEnrolment($id = null){
if($id){ if($id){
$userenrolments = $DB->get_records_sql('select ue.userid,ue.id,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated 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.status=1 and e.courseid='.$id); $userenrolments = $DB->get_records_sql('select ue.userid,ue.id,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated 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.status=1 and e.courseid='.$id);
}else{ }else{
$userenrolments = $DB->get_records_sql('select ue.userid,ue.id,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated 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.status=1'); $userenrolments = $DB->get_records_sql('select ue.id,ue.userid,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated 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.status=1');
} }
return $userenrolments; return $userenrolments;
} }
@ -202,7 +203,7 @@ function sendCancelMail($info){
global $CFG; global $CFG;
$apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'"); $apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'");
$replace = array('firstname'=>$info->firstname,'content'=>$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 = $apply_setting['cancelmailcontent']->value; $body = $apply_setting['cancelmailcontent']->value;
$body = updateMailContent($body,$replace); $body = updateMailContent($body,$replace);
$contact = get_admin(); $contact = get_admin();
@ -214,27 +215,30 @@ function sendConfirmMail($info){
global $CFG; global $CFG;
$apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'"); $apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'");
$replace = array('firstname'=>$info->firstname,'content'=>$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 = $apply_setting['confirmmailcontent']->value; $body = $apply_setting['confirmmailcontent']->value;
$body = updateMailContent($body,$replace); $body = updateMailContent($body,$replace);
$contact = get_admin(); $contact = get_admin();
email_to_user($info, $contact, $apply_setting['confirmmailsubject']->value, '', $body); email_to_user($info, $contact, $apply_setting['confirmmailsubject']->value, '', $body);
} }
function sendConfirmMailToTeachers($courseid,$desc){ function sendConfirmMailToTeachers($courseid,$instanceid,$desc){
global $DB; global $DB;
global $CFG; global $CFG;
global $USER; global $USER;
$apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'"); $apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'");
if($apply_setting['sendmailtoteacher']->value == 1){ if($apply_setting['sendmailtoteacher']->value == 1){
$course = $DB->get_record('course',array('id'=>$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));
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));
$body = '<p>Course: '.$course->fullname.'</p><p>First name: '.$USER->firstname.'</p><p>Last name: '.$USER->lastname.'</p><p>Information: '.$desc.'</p>'; $body = '<p>'. get_string('coursename', 'enrol_apply') .': '.format_string($course->fullname).'</p>';
$body .= '<p>'. get_string('applyuser', 'enrol_apply') .': '.$USER->firstname.' '.$USER->lastname.'</p>';
$body .= '<p>'. get_string('comment', 'enrol_apply') .': '.$desc.'</p>';
$body .= '<p>'. html_writer::link(new moodle_url("/enrol/apply/apply.php", array('id'=>$courseid,'enrolid'=>$instanceid)), get_string('applymanage', 'enrol_apply')).'</p>';
$contact = get_admin(); $contact = get_admin();
$info = $editTeacher; $info = $editTeacher;
$info->coursename = $course->fullname; $info->coursename = $course->fullname;
@ -243,6 +247,31 @@ function sendConfirmMailToTeachers($courseid,$desc){
} }
} }
function sendConfirmMailToManagers($courseid,$desc){
global $DB;
global $CFG;
global $USER;
$apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'");
if($apply_setting['sendmailtomanager']->value == 1){
$course = get_course($courseid);
$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));
foreach($managers as $manager){
$userWithManagerRole = $DB->get_record('user',array('id'=>$manager->userid));
$body = '<p>'. get_string('coursename', 'enrol_apply') .': '.format_string($course->fullname).'</p>';
$body .= '<p>'. get_string('applyuser', 'enrol_apply') .': '.$USER->firstname.' '.$USER->lastname.'</p>';
$body .= '<p>'. get_string('comment', 'enrol_apply') .': '.$desc.'</p>';
$body .= '<p>'. html_writer::link(new moodle_url('/enrol/apply/manage.php'), get_string('applymanage', 'enrol_apply')).'</p>';
$contact = get_admin();
$info = $userWithManagerRole;
$info->coursename = $course->fullname;
email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), '', $body);
}
}
}
function getRelatedInfo($enrolid){ function getRelatedInfo($enrolid){
global $DB; global $DB;
global $CFG; global $CFG;

5
locallib.php

@ -42,6 +42,9 @@ class enrol_apply_enrol_form extends moodleform {
$this->instance = $instance; $this->instance = $instance;
$plugin = enrol_get_plugin('self'); $plugin = enrol_get_plugin('self');
$heading = $plugin->get_instance_name($instance);
$mform->addElement('header', 'selfheader', $heading);
if ($instance->password) { if ($instance->password) {
$heading = $plugin->get_instance_name($instance); $heading = $plugin->get_instance_name($instance);
$mform->addElement('header', 'selfheader', $heading); $mform->addElement('header', 'selfheader', $heading);
@ -53,7 +56,7 @@ class enrol_apply_enrol_form extends moodleform {
} }
$mform->addElement('html', '<p>'.$instance->customtext1.'</p>'); $mform->addElement('html', '<p>'.$instance->customtext1.'</p>');
$mform->addElement('textarea', 'applydescription','','cols="80"'); $mform->addElement('textarea', 'applydescription', get_string('comment', 'enrol_apply'),'cols="80"');
$this->add_action_buttons(false, get_string('enrolme', 'enrol_self')); $this->add_action_buttons(false, get_string('enrolme', 'enrol_self'));
$mform->addElement('hidden', 'id'); $mform->addElement('hidden', 'id');

2
manage.php

@ -50,7 +50,7 @@ echo '<th class="header" scope="col">' . get_string ( 'applydate', 'enrol_apply'
echo '</tr>'; echo '</tr>';
foreach ( $enrols as $enrol ) { foreach ( $enrols as $enrol ) {
echo '<tr><td><input type="checkbox" name="enrolid[]" value="' . $enrol->id . '"></td>'; echo '<tr><td><input type="checkbox" name="enrolid[]" value="' . $enrol->id . '"></td>';
echo '<td>' . $enrol->course . '</td>'; echo '<td>' . format_string($enrol->course) . '</td>';
echo '<td>' . $enrol->firstname . ' ' . $enrol->lastname . '</td>'; echo '<td>' . $enrol->firstname . ' ' . $enrol->lastname . '</td>';
echo '<td>' . $enrol->email . '</td>'; echo '<td>' . $enrol->email . '</td>';
echo '<td>' . date ( "Y-m-d", $enrol->timecreated ) . '</td></tr>'; echo '<td>' . date ( "Y-m-d", $enrol->timecreated ) . '</td></tr>';

4
settings.php

@ -26,8 +26,8 @@ if ($ADMIN->fulltree) {
$settings->add(new admin_setting_heading('enrol_apply_cancelmailcontent', '', get_string('cancelmailcontent_desc', 'enrol_apply'))); $settings->add(new admin_setting_heading('enrol_apply_cancelmailcontent', '', get_string('cancelmailcontent_desc', 'enrol_apply')));
$settings->add(new admin_setting_confightmleditor('enrol_apply/cancelmailcontent', get_string('cancelmailcontent', 'enrol_apply'),'utf-8','')); $settings->add(new admin_setting_confightmleditor('enrol_apply/cancelmailcontent', get_string('cancelmailcontent', 'enrol_apply'),'utf-8',''));
$settings->add(new admin_setting_configcheckbox('enrol_apply/sendmailtoteacher', $settings->add(new admin_setting_configcheckbox('enrol_apply/sendmailtoteacher', get_string('sendmailtoteacher', 'enrol_apply'), '', 0));
get_string('sendmailtoteacher', 'enrol_apply'), '', 0)); $settings->add(new admin_setting_configcheckbox('enrol_apply/sendmailtomanager', get_string('sendmailtomanager', 'enrol_apply'), '', 0));
//--- enrol instance defaults ---------------------------------------------------------------------------- //--- enrol instance defaults ----------------------------------------------------------------------------
$settings->add(new admin_setting_heading('enrol_manual_defaults', $settings->add(new admin_setting_heading('enrol_manual_defaults',

Loading…
Cancel
Save