Browse Source

Merge pull request #29 from emeneo/develop_fields

Applicant must check / enter user profile fields during application process
SABERES_37_STABLE
Flotter Totte 10 years ago
parent
commit
2fb6e11ee1
  1. 0
      .gitignore
  2. 1
      edit_form.php
  3. 4
      lang/en/enrol_apply.php
  4. 100
      lib.php
  5. 33
      locallib.php
  6. 10
      settings.php
  7. 2
      version.php

0
.gitignore

1
edit_form.php

@ -41,7 +41,6 @@ class enrol_self_edit_form extends moodleform {
$mform->setDefault('roleid', $plugin->get_config('roleid'));
$mform->addElement('textarea', 'customtext1', get_string('editdescription', 'enrol_apply'));
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);

4
lang/en/enrol_apply.php

@ -51,4 +51,8 @@ $string['comment'] = 'Comment';
$string['applymanage'] = 'Manage enrolment applications';
$string['status_desc'] = 'Allow course access of internally enrolled users.';
$string['user_profile'] = 'User Profile';
$string['show_standard_user_profile'] = 'Show standard user profile fields on enrolment screen';
$string['show_extra_user_profile'] = 'Show extra user profile fields on enrolment screen';
?>

100
lib.php

@ -78,6 +78,19 @@ class enrol_apply_plugin extends enrol_plugin {
$instanceid = optional_param('instance', 0, PARAM_INT);
if ($instance->id == $instanceid) {
if ($data = $form->get_data()) {
$userInfo = $data;
$applydescription = $userInfo->applydescription;
unset($userInfo->applydescription);
$userInfo->id = $USER->id;
$apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'");
if($apply_setting['show_standard_user_profile']->value == 1 && $apply_setting['show_extra_user_profile']->value == 0){
profile_save_data($userInfo);
//$res = $DB->update_record('user',$userInfoProfile);
}else{
profile_save_data($userInfo);
$res = $DB->update_record('user',$userInfo);
}
$enrol = enrol_get_plugin('self');
$timestart = time();
if ($instance->enrolperiod) {
@ -93,8 +106,8 @@ class enrol_apply_plugin extends enrol_plugin {
}
$this->enrol_user($instance, $USER->id, $roleid, $timestart, $timeend,1);
sendConfirmMailToTeachers($instance->courseid, $instance->id, $data->applydescription);
sendConfirmMailToManagers($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!
redirect("$CFG->wwwroot/course/view.php?id=$instance->courseid");
@ -265,7 +278,7 @@ function sendConfirmMail($info){
email_to_user($info, $contact, $apply_setting['confirmmailsubject']->value, html_to_text($body), $body);
}
function sendConfirmMailToTeachers($courseid,$instanceid,$desc){
function sendConfirmMailToTeachers($courseid,$instanceid,$info,$applydescription){
global $DB;
global $CFG;
global $USER;
@ -280,7 +293,45 @@ function sendConfirmMailToTeachers($courseid,$instanceid,$desc){
$editTeacher = $DB->get_record('user',array('id'=>$teacher->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>'. get_string('comment', 'enrol_apply') .': '.$applydescription.'</p>';
if($apply_setting['show_standard_user_profile']->value == 0){
$body .= '<p><strong>'. get_string('user_profile', 'enrol_apply').'</strong></p>';
$body .= '<p>'. get_string('firstname') .': '.$info->firstname.'</p>';
$body .= '<p>'. get_string('lastname') .': '.$info->lastname.'</p>';
$body .= '<p>'. get_string('email') .': '.$info->email.'</p>';
$body .= '<p>'. get_string('city') .': '.$info->city.'</p>';
$body .= '<p>'. get_string('country') .': '.$info->country.'</p>';
$body .= '<p>'. get_string('preferredlanguage') .': '.$info->lang.'</p>';
$body .= '<p>'. get_string('description') .': '.$info->description_editor['text'].'</p>';
$body .= '<p>'. get_string('firstnamephonetic') .': '.$info->firstnamephonetic.'</p>';
$body .= '<p>'. get_string('lastnamephonetic') .': '.$info->lastnamephonetic.'</p>';
$body .= '<p>'. get_string('middlename') .': '.$info->middlename.'</p>';
$body .= '<p>'. get_string('alternatename') .': '.$info->alternatename.'</p>';
$body .= '<p>'. get_string('url') .': '.$info->url.'</p>';
$body .= '<p>'. get_string('icqnumber') .': '.$info->icq.'</p>';
$body .= '<p>'. get_string('skypeid') .': '.$info->skype.'</p>';
$body .= '<p>'. get_string('aimid') .': '.$info->aim.'</p>';
$body .= '<p>'. get_string('yahooid') .': '.$info->yahoo.'</p>';
$body .= '<p>'. get_string('msnid') .': '.$info->msn.'</p>';
$body .= '<p>'. get_string('idnumber') .': '.$info->idnumber.'</p>';
$body .= '<p>'. get_string('institution') .': '.$info->institution.'</p>';
$body .= '<p>'. get_string('department') .': '.$info->department.'</p>';
$body .= '<p>'. get_string('phone') .': '.$info->phone1.'</p>';
$body .= '<p>'. get_string('phone2') .': '.$info->phone2.'</p>';
$body .= '<p>'. get_string('address') .': '.$info->address.'</p>';
}
if($apply_setting['show_extra_user_profile']->value == 0){
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 .= '<p>'. $key .': '.$value.'</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 = core_user::get_support_user();
$info = $editTeacher;
@ -290,7 +341,7 @@ function sendConfirmMailToTeachers($courseid,$instanceid,$desc){
}
}
function sendConfirmMailToManagers($courseid,$desc){
function sendConfirmMailToManagers($courseid,$info,$applydescription){
global $DB;
global $CFG;
global $USER;
@ -305,7 +356,44 @@ function sendConfirmMailToManagers($courseid,$desc){
$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>'. get_string('comment', 'enrol_apply') .': '.$applydescription.'</p>';
if($apply_setting['show_standard_user_profile']->value == 0){
$body .= '<p><strong>'. get_string('user_profile', 'enrol_apply').'</strong></p>';
$body .= '<p>'. get_string('firstname') .': '.$info->firstname.'</p>';
$body .= '<p>'. get_string('lastname') .': '.$info->lastname.'</p>';
$body .= '<p>'. get_string('email') .': '.$info->email.'</p>';
$body .= '<p>'. get_string('city') .': '.$info->city.'</p>';
$body .= '<p>'. get_string('country') .': '.$info->country.'</p>';
$body .= '<p>'. get_string('preferredlanguage') .': '.$info->lang.'</p>';
$body .= '<p>'. get_string('description') .': '.$info->description_editor['text'].'</p>';
$body .= '<p>'. get_string('firstnamephonetic') .': '.$info->firstnamephonetic.'</p>';
$body .= '<p>'. get_string('lastnamephonetic') .': '.$info->lastnamephonetic.'</p>';
$body .= '<p>'. get_string('middlename') .': '.$info->middlename.'</p>';
$body .= '<p>'. get_string('alternatename') .': '.$info->alternatename.'</p>';
$body .= '<p>'. get_string('url') .': '.$info->url.'</p>';
$body .= '<p>'. get_string('icqnumber') .': '.$info->icq.'</p>';
$body .= '<p>'. get_string('skypeid') .': '.$info->skype.'</p>';
$body .= '<p>'. get_string('aimid') .': '.$info->aim.'</p>';
$body .= '<p>'. get_string('yahooid') .': '.$info->yahoo.'</p>';
$body .= '<p>'. get_string('msnid') .': '.$info->msn.'</p>';
$body .= '<p>'. get_string('idnumber') .': '.$info->idnumber.'</p>';
$body .= '<p>'. get_string('institution') .': '.$info->institution.'</p>';
$body .= '<p>'. get_string('department') .': '.$info->department.'</p>';
$body .= '<p>'. get_string('phone') .': '.$info->phone1.'</p>';
$body .= '<p>'. get_string('phone2') .': '.$info->phone2.'</p>';
$body .= '<p>'. get_string('address') .': '.$info->address.'</p>';
}
if($apply_setting['show_extra_user_profile']->value == 0){
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 .= '<p>'. $key .': '.$value.'</p>';
}
}
$body .= '<p>'. html_writer::link(new moodle_url('/enrol/apply/manage.php'), get_string('applymanage', 'enrol_apply')).'</p>';
$contact = core_user::get_support_user();
$info = $userWithManagerRole;

33
locallib.php

@ -37,6 +37,7 @@ class enrol_apply_enrol_form extends moodleform {
}
public function definition() {
global $DB;
$mform = $this->_form;
$instance = $this->_customdata;
$this->instance = $instance;
@ -57,6 +58,34 @@ class enrol_apply_enrol_form extends moodleform {
$mform->addElement('html', '<p>'.$instance->customtext1.'</p>');
$mform->addElement('textarea', 'applydescription', get_string('comment', 'enrol_apply'),'cols="80"');
//user profile
global $USER,$CFG,$DB;
require_once($CFG->libdir.'/gdlib.php');
require_once($CFG->dirroot.'/user/edit_form.php');
require_once($CFG->dirroot.'/user/editlib.php');
require_once($CFG->dirroot.'/user/profile/lib.php');
require_once($CFG->dirroot.'/user/lib.php');
$user = $DB->get_record('user',array('id'=>$USER->id));
$editoroptions = $filemanageroptions = null;
$apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'");
if($apply_setting['show_standard_user_profile']->value == 0){
useredit_shared_definition($mform, $editoroptions, $filemanageroptions);
}
if($apply_setting['show_extra_user_profile']->value == 0){
profile_definition($mform, $user->id);
}
$profile_default_values = $user;
if (is_object($profile_default_values)) {
$profile_default_values = (array)$profile_default_values;
}
$mform->setDefaults($profile_default_values);
$this->add_action_buttons(false, get_string('enrolme', 'enrol_self'));
$mform->addElement('hidden', 'id');
@ -66,6 +95,10 @@ class enrol_apply_enrol_form extends moodleform {
$mform->addElement('hidden', 'instance');
$mform->setType('instance', PARAM_INT);
$mform->setDefault('instance', $instance->id);
//$mform->addElement('html',"<script type='text/javascript' src='../../lib/jquery/jquery-1.10.2.min.js'></script>");
//$mform->addElement('html','<script>$(document).ready(function(){$(".collapsible-actions a").trigger("click");})</script>');
//$mform->addElement('html','<script type="text/javascript">$(document).ready(function(){setTimeout(function(){$(".collapseexpand").trigger("click");},3000)})</script>');
}
public function validation($data, $files) {

10
settings.php

@ -41,6 +41,16 @@ if ($ADMIN->fulltree) {
$settings->add(new admin_setting_configselect('enrol_apply/status',
get_string('status', 'enrol_apply'), get_string('status_desc', 'enrol_apply'), ENROL_INSTANCE_ENABLED, $options));
$options = array(ENROL_INSTANCE_ENABLED => get_string('yes'),
ENROL_INSTANCE_DISABLED => get_string('no'));
$settings->add(new admin_setting_configselect('enrol_apply/show_standard_user_profile',
get_string('show_standard_user_profile', 'enrol_apply'), '', ENROL_INSTANCE_ENABLED, $options));
$options = array(ENROL_INSTANCE_ENABLED => get_string('yes'),
ENROL_INSTANCE_DISABLED => get_string('no'));
$settings->add(new admin_setting_configselect('enrol_apply/show_extra_user_profile',
get_string('show_extra_user_profile', 'enrol_apply'), '', ENROL_INSTANCE_ENABLED, $options));
if (!during_initial_install()) {
$options = get_default_enrol_roles(context_system::instance());
$student = get_archetype_roles('student');

2
version.php

@ -18,7 +18,7 @@
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2015012500;
$plugin->version = 2015032701;
$plugin->requires = 2011080100;
$plugin->maturity = MATURITY_STABLE;
$plugin->release = 'Course Enrol Apply Plugin Version 1.3.1 (build 2014091000)';

Loading…
Cancel
Save