From b5a4643f35cf24676fda7fd302812bc49c103b39 Mon Sep 17 00:00:00 2001 From: Flottertotte Date: Fri, 17 Apr 2015 17:33:39 +0800 Subject: [PATCH] Enrolment page part --- .gitignore | 0 lang/en/enrol_apply.php | 9 +++ lib.php | 37 ++++++++-- locallib.php | 159 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 197 insertions(+), 8 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/lang/en/enrol_apply.php b/lang/en/enrol_apply.php index f6ea2b0..55ad7f8 100644 --- a/lang/en/enrol_apply.php +++ b/lang/en/enrol_apply.php @@ -51,4 +51,13 @@ $string['comment'] = 'Comment'; $string['applymanage'] = 'Manage enrolment applications'; $string['status_desc'] = 'Allow course access of internally enrolled users.'; +$string['user_profile'] = 'User Profile'; + +$string['firstname'] = 'First name'; +$string['lastname'] = 'Surname'; +$string['email'] = 'Email address'; +$string['city'] = 'City/town'; +$string['country'] = 'Country'; +$string['lang'] = 'Preferred language'; +$string['description_editor'] = 'Description'; ?> \ No newline at end of file diff --git a/lib.php b/lib.php index 4a872e6..c788050 100644 --- a/lib.php +++ b/lib.php @@ -78,6 +78,9 @@ 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; + unset($userInfo->applydescription); + $res = $DB->update_record('user',$userInfo); $enrol = enrol_get_plugin('self'); $timestart = time(); if ($instance->enrolperiod) { @@ -93,8 +96,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); + sendConfirmMailToManagers($instance->courseid,$data); 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 +268,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){ global $DB; global $CFG; global $USER; @@ -279,8 +282,18 @@ function sendConfirmMailToTeachers($courseid,$instanceid,$desc){ 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') .': '.$desc.'

'; + $body .= '

'. get_string('applyuser', 'enrol_apply') .': '.$info->firstname.' '.$info->lastname.'

'; + $body .= '

'. get_string('comment', 'enrol_apply') .': '.$info->applydescription.'

'; + + $body .= '

'. get_string('user_profile', 'enrol_apply').'

'; + $body .= '

'. get_string('firstname', 'enrol_apply') .': '.$info->firstname.'

'; + $body .= '

'. get_string('lastname', 'enrol_apply') .': '.$info->lastname.'

'; + $body .= '

'. get_string('email', 'enrol_apply') .': '.$info->email.'

'; + $body .= '

'. get_string('city', 'enrol_apply') .': '.$info->city.'

'; + $body .= '

'. get_string('country', 'enrol_apply') .': '.$info->country.'

'; + $body .= '

'. get_string('lang', 'enrol_apply') .': '.$info->lang.'

'; + $body .= '

'. get_string('description_editor', 'enrol_apply') .': '.$info->description_editor['text'].'

'; + $body .= '

'. html_writer::link(new moodle_url("/enrol/apply/apply.php", array('id'=>$courseid,'enrolid'=>$instanceid)), get_string('applymanage', 'enrol_apply')).'

'; $contact = core_user::get_support_user(); $info = $editTeacher; @@ -290,7 +303,7 @@ function sendConfirmMailToTeachers($courseid,$instanceid,$desc){ } } -function sendConfirmMailToManagers($courseid,$desc){ +function sendConfirmMailToManagers($courseid,$info){ global $DB; global $CFG; global $USER; @@ -304,8 +317,16 @@ function sendConfirmMailToManagers($courseid,$desc){ 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') .': '.$desc.'

'; + $body .= '

'. get_string('applyuser', 'enrol_apply') .': '.$info->firstname.' '.$info->lastname.'

'; + $body .= '

'. get_string('comment', 'enrol_apply') .': '.$info->applydescription.'

'; + $body .= '

'. get_string('user_profile', 'enrol_apply').'

'; + $body .= '

'. get_string('firstname', 'enrol_apply') .': '.$info->firstname.'

'; + $body .= '

'. get_string('lastname', 'enrol_apply') .': '.$info->lastname.'

'; + $body .= '

'. get_string('email', 'enrol_apply') .': '.$info->email.'

'; + $body .= '

'. get_string('city', 'enrol_apply') .': '.$info->city.'

'; + $body .= '

'. get_string('country', 'enrol_apply') .': '.$info->country.'

'; + $body .= '

'. get_string('lang', 'enrol_apply') .': '.$info->lang.'

'; + $body .= '

'. get_string('description_editor', 'enrol_apply') .': '.$info->description_editor['text'].'

'; $body .= '

'. html_writer::link(new moodle_url('/enrol/apply/manage.php'), get_string('applymanage', 'enrol_apply')).'

'; $contact = core_user::get_support_user(); $info = $userWithManagerRole; diff --git a/locallib.php b/locallib.php index a668aa5..2162dd3 100644 --- a/locallib.php +++ b/locallib.php @@ -57,6 +57,165 @@ class enrol_apply_enrol_form extends moodleform { $mform->addElement('html', '

'.$instance->customtext1.'

'); $mform->addElement('textarea', 'applydescription', get_string('comment', 'enrol_apply'),'cols="80"'); + + //user profile + global $USER,$CFG; + 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 = $USER; + $personalcontext = context_user::instance($user->id); + //profile_load_data($user); + + $mform->addElement('header', 'selfheader', 'User profile'); + //useredit_load_preferences($user, false); + + $strrequired = get_string('required'); + foreach (useredit_get_required_name_fields() as $fullname) { + $mform->addElement('text', $fullname, get_string($fullname), 'maxlength="100" size="30"'); + $mform->addRule($fullname, $strrequired, 'required', null, 'client'); + $mform->setType($fullname, PARAM_NOTAGS); + } + $enabledusernamefields = useredit_get_enabled_name_fields(); + foreach ($enabledusernamefields as $addname) { + $mform->addElement('text', $addname, get_string($addname), 'maxlength="100" size="30"'); + $mform->setType($addname, PARAM_NOTAGS); + } + + //Do not show email field if change confirmation is pending + if (!empty($CFG->emailchangeconfirmation) and !empty($user->preference_newemail)) { + $notice = get_string('emailchangepending', 'auth', $user); + $notice .= '
' + . get_string('emailchangecancel', 'auth') . ''; + $mform->addElement('static', 'emailpending', get_string('email'), $notice); + } else { + $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"'); + $mform->addRule('email', $strrequired, 'required', null, 'client'); + $mform->setType('email', PARAM_EMAIL); + } + + $choices = array(); + $choices['0'] = get_string('emaildisplayno'); + $choices['1'] = get_string('emaildisplayyes'); + $choices['2'] = get_string('emaildisplaycourse'); + $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices); + $mform->setDefault('maildisplay', 2); + + $choices = array(); + $choices['0'] = get_string('textformat'); + $choices['1'] = get_string('htmlformat'); + $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices); + $mform->setDefault('mailformat', 1); + + if (!empty($CFG->allowusermailcharset)) { + $choices = array(); + $charsets = get_list_of_charsets(); + if (!empty($CFG->sitemailcharset)) { + $choices['0'] = get_string('site').' ('.$CFG->sitemailcharset.')'; + } else { + $choices['0'] = get_string('site').' (UTF-8)'; + } + $choices = array_merge($choices, $charsets); + $mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices); + } + + $choices = array(); + $choices['0'] = get_string('emaildigestoff'); + $choices['1'] = get_string('emaildigestcomplete'); + $choices['2'] = get_string('emaildigestsubjects'); + $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices); + $mform->setDefault('maildigest', 0); + $mform->addHelpButton('maildigest', 'emaildigest'); + + $choices = array(); + $choices['1'] = get_string('autosubscribeyes'); + $choices['0'] = get_string('autosubscribeno'); + $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices); + $mform->setDefault('autosubscribe', 1); + + if (!empty($CFG->forum_trackreadposts)) { + $choices = array(); + $choices['0'] = get_string('trackforumsno'); + $choices['1'] = get_string('trackforumsyes'); + $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices); + $mform->setDefault('trackforums', 0); + } + + $editors = editors_get_enabled(); + if (count($editors) > 1) { + $choices = array('' => get_string('defaulteditor')); + $firsteditor = ''; + foreach (array_keys($editors) as $editor) { + if (!$firsteditor) { + $firsteditor = $editor; + } + $choices[$editor] = get_string('pluginname', 'editor_' . $editor); + } + $mform->addElement('select', 'preference_htmleditor', get_string('textediting'), $choices); + $mform->setDefault('preference_htmleditor', ''); + } else { + // Empty string means use the first chosen text editor. + $mform->addElement('hidden', 'preference_htmleditor'); + $mform->setDefault('preference_htmleditor', ''); + $mform->setType('preference_htmleditor', PARAM_PLUGIN); + } + + $mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="21"'); + $mform->setType('city', PARAM_TEXT); + if (!empty($CFG->defaultcity)) { + $mform->setDefault('city', $CFG->defaultcity); + } + + $choices = get_string_manager()->get_list_of_countries(); + $choices= array(''=>get_string('selectacountry').'...') + $choices; + $mform->addElement('select', 'country', get_string('selectacountry'), $choices); + if (!empty($CFG->country)) { + $mform->setDefault('country', $CFG->country); + } + + $choices = get_list_of_timezones(); + $choices['99'] = get_string('serverlocaltime'); + if ($CFG->forcetimezone != 99) { + $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]); + } else { + $mform->addElement('select', 'timezone', get_string('timezone'), $choices); + $mform->setDefault('timezone', '99'); + } + + $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations()); + $mform->setDefault('lang', $CFG->lang); + + // Multi-Calendar Support - see MDL-18375. + $calendartypes = \core_calendar\type_factory::get_list_of_calendar_types(); + // We do not want to show this option unless there is more than one calendar type to display. + if (count($calendartypes) > 1) { + $mform->addElement('select', 'calendartype', get_string('preferredcalendar', 'calendar'), $calendartypes); + } + + if (!empty($CFG->allowuserthemes)) { + $choices = array(); + $choices[''] = get_string('default'); + $themes = get_list_of_themes(); + foreach ($themes as $key=>$theme) { + if (empty($theme->hidefromselector)) { + $choices[$key] = get_string('pluginname', 'theme_'.$theme->name); + } + } + $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices); + } + + $mform->addElement('editor', 'description_editor', get_string('userdescription'), null, null); + $mform->setType('description_editor', PARAM_CLEANHTML); + + $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');