diff --git a/edit.php b/edit.php index 97cee09..c762320 100644 --- a/edit.php +++ b/edit.php @@ -53,6 +53,8 @@ if ($mform->is_cancelled()) { $instance->status = $data->status; $instance->name = $data->name; $instance->customtext1 = $data->customtext1; + $instance->customint1 = $data->customint1; + $instance->customint2 = $data->customint2; $instance->roleid = $data->roleid; $instance->timemodified = time(); $DB->update_record('enrol', $instance); diff --git a/edit_form.php b/edit_form.php index 71db478..7cbec9b 100644 --- a/edit_form.php +++ b/edit_form.php @@ -29,7 +29,7 @@ class enrol_self_edit_form extends moodleform { $options = array(ENROL_INSTANCE_ENABLED => get_string('yes'), ENROL_INSTANCE_DISABLED => get_string('no')); $mform->addElement('select', 'status', get_string('status', 'enrol_apply'), $options); - $mform->addHelpButton('status', 'status', 'enrol_apply'); + //$mform->addHelpButton('status', 'status', 'enrol_apply'); $mform->setDefault('status', $plugin->get_config('status')); if ($instance->id) { @@ -42,6 +42,12 @@ class enrol_self_edit_form extends moodleform { $mform->addElement('textarea', 'customtext1', get_string('editdescription', 'enrol_apply')); + $mform->addElement('select', 'customint1', get_string('show_standard_user_profile', 'enrol_apply'), $options); + $mform->setDefault('customint1', $plugin->get_config('customint1')); + + $mform->addElement('select', 'customint2', get_string('show_extra_user_profile', 'enrol_apply'), $options); + $mform->setDefault('customint2', $plugin->get_config('customint2')); + $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'courseid'); diff --git a/lib.php b/lib.php index 9a63765..a2434f5 100644 --- a/lib.php +++ b/lib.php @@ -84,7 +84,21 @@ class enrol_apply_plugin extends enrol_plugin { $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){ + + $show_standard_user_profile = $show_extra_user_profile = false; + if($instance->customint1 != ''){ + ($instance->customint1 == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false; + }else{ + ($apply_setting['show_standard_user_profile']->value == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false; + } + + if($instance->customint2 != ''){ + ($instance->customint2 == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false; + }else{ + ($apply_setting['show_extra_user_profile']->value == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false; + } + + if(!$show_standard_user_profile && $show_extra_user_profile){ profile_save_data($userInfo); //$res = $DB->update_record('user',$userInfoProfile); }else{ @@ -106,8 +120,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, $data, $applydescription); + sendConfirmMailToManagers($instance, $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"); @@ -278,11 +292,27 @@ function sendConfirmMail($info){ email_to_user($info, $contact, $apply_setting['confirmmailsubject']->value, html_to_text($body), $body); } -function sendConfirmMailToTeachers($courseid,$instanceid,$info,$applydescription){ +function sendConfirmMailToTeachers($instance,$info,$applydescription){ global $DB; global $CFG; global $USER; + + $courseid = $instance->courseid; + $instanceid = $instance->id; $apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'"); + + $show_standard_user_profile = $show_extra_user_profile = false; + if($instance->customint1 != ''){ + ($instance->customint1 == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false; + }else{ + ($apply_setting['show_standard_user_profile']->value == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false; + } + + if($instance->customint2 != ''){ + ($instance->customint2 == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false; + }else{ + ($apply_setting['show_extra_user_profile']->value == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false; + } if($apply_setting['sendmailtoteacher']->value == 1){ $course = get_course($courseid); @@ -295,7 +325,7 @@ function sendConfirmMailToTeachers($courseid,$instanceid,$info,$applydescription $body .= '
'. get_string('applyuser', 'enrol_apply') .': '.$USER->firstname.' '.$USER->lastname.'
'; $body .= ''. get_string('comment', 'enrol_apply') .': '.$applydescription.'
'; - if($apply_setting['show_standard_user_profile']->value == 0){ + if($show_standard_user_profile){ $body .= ''. get_string('user_profile', 'enrol_apply').'
'; $body .= ''. get_string('firstname') .': '.$info->firstname.'
'; $body .= ''. get_string('lastname') .': '.$info->lastname.'
'; @@ -323,7 +353,7 @@ function sendConfirmMailToTeachers($courseid,$instanceid,$info,$applydescription $body .= ''. get_string('address') .': '.$info->address.'
'; } - if($apply_setting['show_extra_user_profile']->value == 0){ + if($show_extra_user_profile){ require_once($CFG->dirroot.'/user/profile/lib.php'); $user = $DB->get_record('user',array('id'=>$USER->id)); profile_load_custom_fields($user); @@ -341,12 +371,27 @@ function sendConfirmMailToTeachers($courseid,$instanceid,$info,$applydescription } } -function sendConfirmMailToManagers($courseid,$info,$applydescription){ +function sendConfirmMailToManagers($instance,$info,$applydescription){ global $DB; global $CFG; global $USER; + + $courseid = $instance->courseid; $apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'"); + $show_standard_user_profile = $show_extra_user_profile = false; + if($instance->customint1 != ''){ + ($instance->customint1 == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false; + }else{ + ($apply_setting['show_standard_user_profile']->value == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false; + } + + if($instance->customint2 != ''){ + ($instance->customint2 == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false; + }else{ + ($apply_setting['show_extra_user_profile']->value == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false; + } + if($apply_setting['sendmailtomanager']->value == 1){ $course = get_course($courseid); $context = context_system::instance(); @@ -357,7 +402,7 @@ function sendConfirmMailToManagers($courseid,$info,$applydescription){ $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($apply_setting['show_standard_user_profile']->value == 0){ + if($show_standard_user_profile){ $body .= ''. get_string('user_profile', 'enrol_apply').'
'; $body .= ''. get_string('firstname') .': '.$info->firstname.'
'; $body .= ''. get_string('lastname') .': '.$info->lastname.'
'; @@ -385,7 +430,7 @@ function sendConfirmMailToManagers($courseid,$info,$applydescription){ $body .= ''. get_string('address') .': '.$info->address.'
'; } - if($apply_setting['show_extra_user_profile']->value == 0){ + if($show_extra_user_profile){ require_once($CFG->dirroot.'/user/profile/lib.php'); $user = $DB->get_record('user',array('id'=>$USER->id)); profile_load_custom_fields($user); diff --git a/locallib.php b/locallib.php index 439dc98..ab9c828 100644 --- a/locallib.php +++ b/locallib.php @@ -72,11 +72,24 @@ class enrol_apply_enrol_form extends moodleform { $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){ + $show_standard_user_profile = $show_extra_user_profile = false; + if($instance->customint1 != ''){ + ($instance->customint1 == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false; + }else{ + ($apply_setting['show_standard_user_profile']->value == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false; + } + + if($instance->customint2 != ''){ + ($instance->customint2 == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false; + }else{ + ($apply_setting['show_extra_user_profile']->value == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false; + } + + if($show_standard_user_profile){ useredit_shared_definition($mform, $editoroptions, $filemanageroptions); } - if($apply_setting['show_extra_user_profile']->value == 0){ + if($show_extra_user_profile){ profile_definition($mform, $user->id); }