From f4bb716a64873af5f1b98e56519b415544c77749 Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Tue, 12 Apr 2016 10:20:10 +0200 Subject: [PATCH 01/28] Indention convert to spaces --- apply.php | 68 ++-- db/access.php | 3 - db/install.php | 41 --- edit.php | 2 +- edit_form.php | 4 +- enroluser.php | 18 +- lib.php | 866 ++++++++++++++++++++++++------------------------ locallib.php | 4 +- manage.php | 28 +- settings.php | 4 +- unenrolself.php | 8 +- unenroluser.php | 4 +- version.php | 3 +- 13 files changed, 505 insertions(+), 548 deletions(-) delete mode 100644 db/install.php diff --git a/apply.php b/apply.php index 9910698..ba13992 100644 --- a/apply.php +++ b/apply.php @@ -1,7 +1,7 @@ set_title ( "$site->shortname: " . get_string ( 'confirmusers', 'enrol_ap $userenrolments = optional_param_array('userenrolments', null, PARAM_INT); if ($userenrolments != null) { - if ($_POST ['type'] == 'confirm') { - confirmEnrolment($userenrolments); - } elseif ($_POST ['type'] == 'wait') { - waitEnrolment ($userenrolments); - } elseif ($_POST ['type'] == 'cancel') { - cancelEnrolment($userenrolments); - } - redirect ( "$CFG->wwwroot/enrol/apply/apply.php?id=" . $id . "&enrolid=" . $enrolid ); + if ($_POST ['type'] == 'confirm') { + confirmEnrolment($userenrolments); + } elseif ($_POST ['type'] == 'wait') { + waitEnrolment ($userenrolments); + } elseif ($_POST ['type'] == 'cancel') { + cancelEnrolment($userenrolments); + } + redirect ( "$CFG->wwwroot/enrol/apply/apply.php?id=" . $id . "&enrolid=" . $enrolid ); } $enrols = getAllEnrolment ($enrolid); $applicationinfo = $DB->get_records_sql(' - SELECT userenrolmentid, comment - FROM {enrol_apply_applicationinfo} - WHERE userenrolmentid IN ( - SELECT id - FROM {user_enrolments} - WHERE enrolid = ?)', array($enrolid)); + SELECT userenrolmentid, comment + FROM {enrol_apply_applicationinfo} + WHERE userenrolmentid IN ( + SELECT id + FROM {user_enrolments} + WHERE enrolid = ?)', array($enrolid)); echo $OUTPUT->header (); echo $OUTPUT->heading ( get_string ( 'confirmusers', 'enrol_apply' ) ); @@ -71,20 +71,20 @@ echo '' . get_string ( 'applydate', 'enrol_apply' echo '' . get_string ( 'comment', 'enrol_apply' ) . ''; echo ''; foreach ( $enrols as $enrol ) { - $picture = get_user_picture($enrol->userid); - if ($enrol->status == 2) { - echo ''; - } else { - echo ''; - } - echo ''; - echo '' . format_string($enrol->course) . ''; - echo '' . $OUTPUT->render($picture) . ''; - echo ''.$enrol->firstname . ' ' . $enrol->lastname.''; - echo '' . $enrol->email . ''; - echo '' . date ( "Y-m-d", $enrol->timecreated ) . ''; - echo '' . htmlspecialchars($applicationinfo[$enrol->id]->comment) . ''; - echo ''; + $picture = get_user_picture($enrol->userid); + if ($enrol->status == 2) { + echo ''; + } else { + echo ''; + } + echo ''; + echo '' . format_string($enrol->course) . ''; + echo '' . $OUTPUT->render($picture) . ''; + echo ''.$enrol->firstname . ' ' . $enrol->lastname.''; + echo '' . $enrol->email . ''; + echo '' . date ( "Y-m-d", $enrol->timecreated ) . ''; + echo '' . htmlspecialchars($applicationinfo[$enrol->id]->comment) . ''; + echo ''; } echo ''; echo '

'; @@ -94,19 +94,19 @@ echo ''; echo $OUTPUT->footer (); function get_user_picture($userid){ - global $DB; + global $DB; $extrafields[] = 'lastaccess'; $ufields = user_picture::fields('u', $extrafields); - $sql = "SELECT DISTINCT $ufields FROM {user} u where u.id=$userid"; + $sql = "SELECT DISTINCT $ufields FROM {user} u where u.id=$userid"; $user = $DB->get_record_sql($sql); - return new user_picture($user); + return new user_picture($user); } \ No newline at end of file diff --git a/db/access.php b/db/access.php index 0263294..bb8818d 100644 --- a/db/access.php +++ b/db/access.php @@ -78,7 +78,4 @@ $capabilities = array( 'student' => CAP_ALLOW, ) ), - ); - - diff --git a/db/install.php b/db/install.php deleted file mode 100644 index 7ecd509..0000000 --- a/db/install.php +++ /dev/null @@ -1,41 +0,0 @@ -sendcoursewelcomemessage)) { - set_config('sendcoursewelcomemessage', $CFG->sendcoursewelcomemessage, 'enrol_apply'); // new course default - $DB->set_field('enrol', 'customint4', $CFG->sendcoursewelcomemessage, array('enrol'=>'apply')); // each instance has different setting now - unset_config('sendcoursewelcomemessage'); - } - - // migrate long-time-no-see feature settings - if (isset($CFG->longtimenosee)) { - $nosee = $CFG->longtimenosee * 3600 * 24; - set_config('longtimenosee', $nosee, 'enrol_apply'); - $DB->set_field('enrol', 'customint2', $nosee, array('enrol'=>'apply')); - unset_config('longtimenosee'); - } -} diff --git a/edit.php b/edit.php index 126ef35..d8b9626 100644 --- a/edit.php +++ b/edit.php @@ -2,7 +2,7 @@ /** * ************************************************************************* - * * Apply Enrol ** + * * Apply Enrol ** * ************************************************************************* * @copyright emeneo.com ** * @link emeneo.com ** diff --git a/edit_form.php b/edit_form.php index cdaaa4d..07b7466 100644 --- a/edit_form.php +++ b/edit_form.php @@ -2,7 +2,7 @@ /** * ************************************************************************* - * * Apply Enrol ** + * * Apply Enrol ** * ************************************************************************* * @copyright emeneo.com ** * @link emeneo.com ** @@ -40,7 +40,7 @@ class enrol_self_edit_form extends moodleform { $mform->addElement('select', 'roleid', get_string('defaultrole', 'role'), $roles); $mform->setDefault('roleid', $plugin->get_config('roleid')); - $mform->addElement('textarea', 'customtext1', get_string('editdescription', 'enrol_apply')); + $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')); diff --git a/enroluser.php b/enroluser.php index a7e9c7a..901f135 100644 --- a/enroluser.php +++ b/enroluser.php @@ -1,7 +1,7 @@ ";print_r($instance);exit(); $enrol_manual->enrol_user($instance, $adduser->id, $roleid, $timestart, $timeend); - // Deprecated fixed by Shiro - //add_to_log($course->id, 'course', 'enrol', '../enrol/users.php?id='.$course->id, $course->id); //there should be userid somewhere! - $context = context_course::instance($course->id); - \core\event\user_enrolment_created::create(array('context' => $context))->trigger(); + // Deprecated fixed by Shiro + //add_to_log($course->id, 'course', 'enrol', '../enrol/users.php?id='.$course->id, $course->id); //there should be userid somewhere! + $context = context_course::instance($course->id); + \core\event\user_enrolment_created::create(array('context' => $context))->trigger(); } $potentialuserselector->invalidate_selected_users(); @@ -125,10 +125,10 @@ if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) { foreach($userstounassign as $removeuser) { $enrol_manual->unenrol_user($instance, $removeuser->id); - // Deprecated fixed by Shiro - //add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //there should be userid somewhere! - $context = context_course::instance($course->id); - \core\event\user_enrolment_deleted::delete(array('context' => $context))->trigger(); + // Deprecated fixed by Shiro + //add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //there should be userid somewhere! + $context = context_course::instance($course->id); + \core\event\user_enrolment_deleted::delete(array('context' => $context))->trigger(); } $potentialuserselector->invalidate_selected_users(); diff --git a/lib.php b/lib.php index 5a370a9..aa27236 100644 --- a/lib.php +++ b/lib.php @@ -1,7 +1,7 @@ get_instance_defaults(); - return $this->add_instance($course, $fields); - } - - public function allow_unenrol(stdClass $instance) { - // users with unenrol cap may unenrol other users manually manually - return true; - } - - public function get_newinstance_link($courseid) { - $context = context_course::instance($courseid, MUST_EXIST); - - if (!has_capability('moodle/course:enrolconfig', $context) or !has_capability('enrol/apply:config', $context)) { - return NULL; - } - // multiple instances supported - different roles with different password - return new moodle_url('/enrol/apply/edit.php', array('courseid'=>$courseid)); - } - - public function enrol_page_hook(stdClass $instance) { - global $CFG, $OUTPUT, $SESSION, $USER, $DB; - - if (isguestuser()) { - // can not enrol guest!! - return null; - } - if ($DB->record_exists('user_enrolments', array('userid'=>$USER->id, 'enrolid'=>$instance->id))) { - //TODO: maybe we should tell them they are already enrolled, but can not access the course - //return null; - return $OUTPUT->notification(get_string('notification', 'enrol_apply'), 'notifysuccess'); - } + /** + * Add new instance of enrol plugin with default settings. + * @param object $course + * @return int id of new instance + */ + public function add_default_instance($course) { + $fields = $this->get_instance_defaults(); + return $this->add_instance($course, $fields); + } + + public function allow_unenrol(stdClass $instance) { + // users with unenrol cap may unenrol other users manually manually + return true; + } + + public function get_newinstance_link($courseid) { + $context = context_course::instance($courseid, MUST_EXIST); + + if (!has_capability('moodle/course:enrolconfig', $context) or !has_capability('enrol/apply:config', $context)) { + return NULL; + } + // multiple instances supported - different roles with different password + return new moodle_url('/enrol/apply/edit.php', array('courseid'=>$courseid)); + } + + public function enrol_page_hook(stdClass $instance) { + global $CFG, $OUTPUT, $SESSION, $USER, $DB; + + if (isguestuser()) { + // can not enrol guest!! + return null; + } + if ($DB->record_exists('user_enrolments', array('userid'=>$USER->id, 'enrolid'=>$instance->id))) { + //TODO: maybe we should tell them they are already enrolled, but can not access the course + //return null; + return $OUTPUT->notification(get_string('notification', 'enrol_apply'), 'notifysuccess'); + } require_once("$CFG->dirroot/enrol/apply/locallib.php"); - $form = new enrol_apply_enrol_form(NULL, $instance); - - $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'"); - - $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); - //$res = $DB->update_record('user',$userInfo); - } - /*elseif($show_standard_user_profile && $show_extra_user_profile){ - profile_save_data($userInfo); - $res = $DB->update_record('user',$userInfo); - }*/ - - $enrol = enrol_get_plugin('self'); - $timestart = time(); - if ($instance->enrolperiod) { - $timeend = $timestart + $instance->enrolperiod; - } else { - $timeend = 0; - } - - $roleid = $instance->roleid; - if(!$roleid){ - $role = $DB->get_record_sql("select * from ".$CFG->prefix."role where archetype='student' limit 1"); - $roleid = $role->id; - } - - $this->enrol_user($instance, $USER->id, $roleid, $timestart, $timeend,1); - $userenrolment = $DB->get_record('user_enrolments', array('userid' => $USER->id, 'enrolid' => $instance->id), 'id', MUST_EXIST); - $applicationinfo = new stdClass(); - $applicationinfo->userenrolmentid = $userenrolment->id; - $applicationinfo->comment = $applydescription; - $DB->insert_record('enrol_apply_applicationinfo', $applicationinfo, false); - sendConfirmMailToTeachers($instance, $data, $applydescription); - sendConfirmMailToManagers($instance, $data, $applydescription); - - // Deprecated fixed by Shiro - //add_to_log($instance->courseid, 'course', 'enrol', '../enrol/users.php?id='.$instance->courseid, $instance->courseid); //there should be userid somewhere! - $context = context_course::instance($instance->courseid); - \core\event\user_enrolment_created::create( - array( - 'objectid' => $instance->id, - 'courseid' => $instance->courseid, - 'context' => $context, - 'relateduserid' => $USER->id, - 'other' => array('enrol' => 'apply') - ))->trigger(); - - redirect("$CFG->wwwroot/course/view.php?id=$instance->courseid"); - } - } - //exit; - ob_start(); - $form->display(); - $output = ob_get_clean(); - - return $OUTPUT->box($output); - - } - - public function get_action_icons(stdClass $instance) { - global $OUTPUT; - - if ($instance->enrol !== 'apply') { - throw new coding_exception('invalid enrol instance!'); - } - $context = context_course::instance($instance->courseid); - - $icons = array(); - - if (has_capability('enrol/apply:config', $context)) { + $form = new enrol_apply_enrol_form(NULL, $instance); + + $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'"); + + $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); + //$res = $DB->update_record('user',$userInfo); + } + /*elseif($show_standard_user_profile && $show_extra_user_profile){ + profile_save_data($userInfo); + $res = $DB->update_record('user',$userInfo); + }*/ + + $enrol = enrol_get_plugin('self'); + $timestart = time(); + if ($instance->enrolperiod) { + $timeend = $timestart + $instance->enrolperiod; + } else { + $timeend = 0; + } + + $roleid = $instance->roleid; + if(!$roleid){ + $role = $DB->get_record_sql("select * from ".$CFG->prefix."role where archetype='student' limit 1"); + $roleid = $role->id; + } + + $this->enrol_user($instance, $USER->id, $roleid, $timestart, $timeend,1); + $userenrolment = $DB->get_record('user_enrolments', array('userid' => $USER->id, 'enrolid' => $instance->id), 'id', MUST_EXIST); + $applicationinfo = new stdClass(); + $applicationinfo->userenrolmentid = $userenrolment->id; + $applicationinfo->comment = $applydescription; + $DB->insert_record('enrol_apply_applicationinfo', $applicationinfo, false); + sendConfirmMailToTeachers($instance, $data, $applydescription); + sendConfirmMailToManagers($instance, $data, $applydescription); + + // Deprecated fixed by Shiro + //add_to_log($instance->courseid, 'course', 'enrol', '../enrol/users.php?id='.$instance->courseid, $instance->courseid); //there should be userid somewhere! + $context = context_course::instance($instance->courseid); + \core\event\user_enrolment_created::create( + array( + 'objectid' => $instance->id, + 'courseid' => $instance->courseid, + 'context' => $context, + 'relateduserid' => $USER->id, + 'other' => array('enrol' => 'apply') + ))->trigger(); + + redirect("$CFG->wwwroot/course/view.php?id=$instance->courseid"); + } + } + //exit; + ob_start(); + $form->display(); + $output = ob_get_clean(); + + return $OUTPUT->box($output); + + } + + public function get_action_icons(stdClass $instance) { + global $OUTPUT; + + if ($instance->enrol !== 'apply') { + throw new coding_exception('invalid enrol instance!'); + } + $context = context_course::instance($instance->courseid); + + $icons = array(); + + if (has_capability('enrol/apply:config', $context)) { $editlink = new moodle_url("/enrol/apply/edit.php", array('courseid'=>$instance->courseid, 'id'=>$instance->id)); $icons[] = $OUTPUT->action_icon($editlink, new pix_icon('t/edit', get_string('edit'), 'core', array('class' => 'iconsmall'))); } - if (has_capability('enrol/apply:manage', $context)) { - $managelink = new moodle_url("/enrol/apply/apply.php", array('id'=>$_GET['id'],'enrolid'=>$instance->id)); - $icons[] = $OUTPUT->action_icon($managelink, new pix_icon('i/users', get_string('confirmenrol', 'enrol_apply'), 'core', array('class'=>'iconsmall'))); - } + if (has_capability('enrol/apply:manage', $context)) { + $managelink = new moodle_url("/enrol/apply/apply.php", array('id'=>$_GET['id'],'enrolid'=>$instance->id)); + $icons[] = $OUTPUT->action_icon($managelink, new pix_icon('i/users', get_string('confirmenrol', 'enrol_apply'), 'core', array('class'=>'iconsmall'))); + } - if (has_capability("enrol/apply:enrol", $context)) { - $enrollink = new moodle_url("/enrol/apply/enroluser.php", array('enrolid'=>$instance->id)); - $icons[] = $OUTPUT->action_icon($enrollink, new pix_icon('t/enrolusers', get_string('enrolusers', 'enrol_apply'), 'core', array('class'=>'iconsmall'))); - } - - return $icons; - } + if (has_capability("enrol/apply:enrol", $context)) { + $enrollink = new moodle_url("/enrol/apply/enroluser.php", array('enrolid'=>$instance->id)); + $icons[] = $OUTPUT->action_icon($enrollink, new pix_icon('t/enrolusers', get_string('enrolusers', 'enrol_apply'), 'core', array('class'=>'iconsmall'))); + } + + return $icons; + } /** - * Is it possible to hide/show enrol instance via standard UI? - * - * @param stdClass $instance - * @return bool - */ - public function can_hide_show_instance($instance) { - $context = context_course::instance($instance->courseid); - return has_capability('enrol/apply:config', $context); - } - - /** - * Is it possible to delete enrol instance via standard UI? - * - * @param stdClass $instance - * @return bool - */ - - public function can_delete_instance($instance) { - $context = context_course::instance($instance->courseid); - return has_capability('enrol/apply:config', $context); - } - - - /** - * Sets up navigation entries. - * - * @param stdClass $instancesnode - * @param stdClass $instance - * @return void - */ - public function add_course_navigation($instancesnode, stdClass $instance) { + * Is it possible to hide/show enrol instance via standard UI? + * + * @param stdClass $instance + * @return bool + */ + public function can_hide_show_instance($instance) { + $context = context_course::instance($instance->courseid); + return has_capability('enrol/apply:config', $context); + } + + /** + * Is it possible to delete enrol instance via standard UI? + * + * @param stdClass $instance + * @return bool + */ + + public function can_delete_instance($instance) { + $context = context_course::instance($instance->courseid); + return has_capability('enrol/apply:config', $context); + } + + + /** + * Sets up navigation entries. + * + * @param stdClass $instancesnode + * @param stdClass $instance + * @return void + */ + public function add_course_navigation($instancesnode, stdClass $instance) { if ($instance->enrol !== 'apply') { throw new coding_exception('Invalid enrol instance type!'); } @@ -204,43 +204,43 @@ class enrol_apply_plugin extends enrol_plugin { } } - public function get_user_enrolment_actions(course_enrolment_manager $manager, $ue) { - $actions = array(); - $context = $manager->get_context(); - $instance = $ue->enrolmentinstance; - $params = $manager->get_moodlepage()->url->params(); - $params['ue'] = $ue->id; - if ($this->allow_unenrol($instance) && has_capability("enrol/apply:unenrol", $context)) { - $url = new moodle_url('/enrol/apply/unenroluser.php', $params); - $actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, array('class'=>'unenrollink', 'rel'=>$ue->id)); - } - if ($this->allow_manage($instance) && has_capability("enrol/apply:manage", $context)) { - $url = new moodle_url('/enrol/apply/editenrolment.php', $params); - $actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, array('class'=>'editenrollink', 'rel'=>$ue->id)); - } - return $actions; - } - - /** - * Returns defaults for new instances. - * @return array - */ - public function get_instance_defaults() { - $fields = array(); - $fields['status'] = $this->get_config('status'); - $fields['roleid'] = $this->get_config('roleid', 0); - $fields['customint1'] = $this->get_config('show_standard_user_profile'); - $fields['customint2'] = $this->get_config('show_extra_user_profile'); - $fields['customint3'] = $this->get_config('sendmailtoteacher'); - $fields['customint4'] = $this->get_config('sendmailtomanager'); - - return $fields; - } + public function get_user_enrolment_actions(course_enrolment_manager $manager, $ue) { + $actions = array(); + $context = $manager->get_context(); + $instance = $ue->enrolmentinstance; + $params = $manager->get_moodlepage()->url->params(); + $params['ue'] = $ue->id; + if ($this->allow_unenrol($instance) && has_capability("enrol/apply:unenrol", $context)) { + $url = new moodle_url('/enrol/apply/unenroluser.php', $params); + $actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, array('class'=>'unenrollink', 'rel'=>$ue->id)); + } + if ($this->allow_manage($instance) && has_capability("enrol/apply:manage", $context)) { + $url = new moodle_url('/enrol/apply/editenrolment.php', $params); + $actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, array('class'=>'editenrollink', 'rel'=>$ue->id)); + } + return $actions; + } + + /** + * Returns defaults for new instances. + * @return array + */ + public function get_instance_defaults() { + $fields = array(); + $fields['status'] = $this->get_config('status'); + $fields['roleid'] = $this->get_config('roleid', 0); + $fields['customint1'] = $this->get_config('show_standard_user_profile'); + $fields['customint2'] = $this->get_config('show_extra_user_profile'); + $fields['customint3'] = $this->get_config('sendmailtoteacher'); + $fields['customint4'] = $this->get_config('sendmailtomanager'); + + return $fields; + } } function getAllEnrolment($id = null) { - global $DB; - if ($id) { + global $DB; + if ($id) { $sql = 'SELECT ue.userid,ue.id,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated,ue.status FROM {course} c JOIN {enrol} e @@ -252,7 +252,7 @@ function getAllEnrolment($id = null) { WHERE ue.status != 0 AND e.id = ?'; $userenrolments = $DB->get_records_sql($sql, array($id)); - } else { + } else { $sql = 'SELECT ue.id,ue.userid,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated FROM {user_enrolments} ue LEFT JOIN {user} u @@ -264,263 +264,263 @@ function getAllEnrolment($id = null) { WHERE ue.status != 0 AND e.enrol = ?'; $userenrolments = $DB->get_records_sql($sql, array('apply')); - } - return $userenrolments; + } + return $userenrolments; } function confirmEnrolment($enrols){ - global $DB; - global $CFG; - foreach ($enrols as $enrol){ - @$enroluser->id = $enrol; - @$enroluser->status = 0; - - if($DB->update_record('user_enrolments',$enroluser)){ - $userenrolments = $DB->get_record_sql('select * from '.$CFG->prefix.'user_enrolments where id='.$enrol); - $role = $DB->get_record_sql("select * from ".$CFG->prefix."role where archetype='student' limit 1"); - @$roleAssignments->userid = $userenrolments->userid; - @$roleAssignments->roleid = $role->id; - @$roleAssignments->contextid = 3; - @$roleAssignments->timemodified = time(); - @$roleAssignments->modifierid = 2; - $DB->insert_record('role_assignments',$roleAssignments); - $info = getRelatedInfo($enrol); - $DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol)); - sendConfirmMail($info); - } - } + global $DB; + global $CFG; + foreach ($enrols as $enrol){ + @$enroluser->id = $enrol; + @$enroluser->status = 0; + + if($DB->update_record('user_enrolments',$enroluser)){ + $userenrolments = $DB->get_record_sql('select * from '.$CFG->prefix.'user_enrolments where id='.$enrol); + $role = $DB->get_record_sql("select * from ".$CFG->prefix."role where archetype='student' limit 1"); + @$roleAssignments->userid = $userenrolments->userid; + @$roleAssignments->roleid = $role->id; + @$roleAssignments->contextid = 3; + @$roleAssignments->timemodified = time(); + @$roleAssignments->modifierid = 2; + $DB->insert_record('role_assignments',$roleAssignments); + $info = getRelatedInfo($enrol); + $DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol)); + sendConfirmMail($info); + } + } } function waitEnrolment($enrols){ - global $DB; - global $CFG; - foreach ($enrols as $enrol){ - @$enroluser->id = $enrol; - @$enroluser->status = 2; - - if($DB->update_record('user_enrolments',$enroluser)){ - $info = getRelatedInfo($enrol); - sendWaitMail($info); - } - } + global $DB; + global $CFG; + foreach ($enrols as $enrol){ + @$enroluser->id = $enrol; + @$enroluser->status = 2; + + if($DB->update_record('user_enrolments',$enroluser)){ + $info = getRelatedInfo($enrol); + sendWaitMail($info); + } + } } function cancelEnrolment($enrols){ - global $DB; - foreach ($enrols as $enrol){ - $info = getRelatedInfo($enrol); - if($DB->delete_records('user_enrolments',array('id'=>$enrol))){ - $DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol)); - sendCancelMail($info); - } - } + global $DB; + foreach ($enrols as $enrol){ + $info = getRelatedInfo($enrol); + if($DB->delete_records('user_enrolments',array('id'=>$enrol))){ + $DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol)); + sendCancelMail($info); + } + } } function sendCancelMail($info){ - global $DB; - global $CFG; - $apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'"); - - $replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); - $body = $apply_setting['cancelmailcontent']->value; - $body = updateMailContent($body,$replace); - $contact = core_user::get_support_user(); - email_to_user($info, $contact, $apply_setting['cancelmailsubject']->value, html_to_text($body), $body); + global $DB; + global $CFG; + $apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'"); + + $replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); + $body = $apply_setting['cancelmailcontent']->value; + $body = updateMailContent($body,$replace); + $contact = core_user::get_support_user(); + email_to_user($info, $contact, $apply_setting['cancelmailsubject']->value, html_to_text($body), $body); } function sendConfirmMail($info){ - global $DB; - global $CFG; - $apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'"); - - $replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); - $body = $apply_setting['confirmmailcontent']->value; - $body = updateMailContent($body,$replace); - $contact = core_user::get_support_user(); - email_to_user($info, $contact, $apply_setting['confirmmailsubject']->value, html_to_text($body), $body); + global $DB; + global $CFG; + $apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'"); + + $replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); + $body = $apply_setting['confirmmailcontent']->value; + $body = updateMailContent($body,$replace); + $contact = core_user::get_support_user(); + email_to_user($info, $contact, $apply_setting['confirmmailsubject']->value, html_to_text($body), $body); } function sendWaitMail($info){ - global $DB; - global $CFG; + global $DB; + global $CFG; //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'"); - $replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); - $body = get_config('enrol_apply', 'waitmailcontent'); - $body = updateMailContent($body,$replace); - $contact = get_admin(); + $replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); + $body = get_config('enrol_apply', 'waitmailcontent'); + $body = updateMailContent($body,$replace); + $contact = get_admin(); //confirm mail will sent by the admin //$contact = $USER; - email_to_user($info, $contact, get_config('enrol_apply', 'waitmailsubject'), html_to_text($body), $body); + email_to_user($info, $contact, get_config('enrol_apply', 'waitmailsubject'), html_to_text($body), $body); } 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($instance->customint3 == 1){ - $course = get_course($courseid); - $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)); - 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($show_standard_user_profile){ - $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($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); - foreach ($user->profile as $key => $value) { - $body .= '

'. $key .': '.$value.'

'; - } - } - - $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; - $info->coursename = $course->fullname; - email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body); - } - } + 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($instance->customint3 == 1){ + $course = get_course($courseid); + $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)); + 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($show_standard_user_profile){ + $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($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); + foreach ($user->profile as $key => $value) { + $body .= '

'. $key .': '.$value.'

'; + } + } + + $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; + $info->coursename = $course->fullname; + email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body); + } + } } 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(); - $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 = '

'. 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($show_standard_user_profile){ - $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($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); - 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); - } - } + 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(); + $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 = '

'. 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($show_standard_user_profile){ + $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($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); + 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); + } + } } function getRelatedInfo($enrolid){ - global $DB; - global $CFG; - return $DB->get_record_sql('select u.*,c.fullname as coursename 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.id='.$enrolid); + global $DB; + global $CFG; + return $DB->get_record_sql('select u.*,c.fullname as coursename 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.id='.$enrolid); } function updateMailContent($content,$replace){ - foreach ($replace as $key=>$val) { - $content = str_replace("{".$key."}",$val,$content); - } - return $content; + foreach ($replace as $key=>$val) { + $content = str_replace("{".$key."}",$val,$content); + } + return $content; } diff --git a/locallib.php b/locallib.php index b84fda8..4ee596a 100644 --- a/locallib.php +++ b/locallib.php @@ -2,7 +2,7 @@ /** * ************************************************************************* - * * Apply Enrol ** + * * Apply Enrol ** * ************************************************************************* * @copyright emeneo.com ** * @link emeneo.com ** @@ -56,7 +56,7 @@ class enrol_apply_enrol_form extends moodleform { // nothing? } - $mform->addElement('html', '

'.$instance->customtext1.'

'); + $mform->addElement('html', '

'.$instance->customtext1.'

'); $mform->addElement('textarea', 'applydescription', get_string('comment', 'enrol_apply'),'cols="80"'); //user profile diff --git a/manage.php b/manage.php index 26050ba..5da4902 100644 --- a/manage.php +++ b/manage.php @@ -1,7 +1,7 @@ navbar->add ( get_string ( 'confirmusers', 'enrol_apply' ) ); $PAGE->set_title ( "$site->shortname: " . get_string ( 'confirmusers', 'enrol_apply' ) ); if (isset ( $_POST ['enrolid'] )) { - if ($_POST ['enrolid']) { - if ($_POST ['type'] == 'confirm') { - confirmEnrolment ( $_POST ['enrolid'] ); - } elseif ($_POST ['type'] == 'cancel') { - cancelEnrolment ( $_POST ['enrolid'] ); - } - redirect ( "$CFG->wwwroot/enrol/apply/manage.php" ); - } + if ($_POST ['enrolid']) { + if ($_POST ['type'] == 'confirm') { + confirmEnrolment ( $_POST ['enrolid'] ); + } elseif ($_POST ['type'] == 'cancel') { + cancelEnrolment ( $_POST ['enrolid'] ); + } + redirect ( "$CFG->wwwroot/enrol/apply/manage.php" ); + } } $enrols = getAllEnrolment(); @@ -49,11 +49,11 @@ echo '' . get_string ( 'applyusermail', 'enrol_ap echo '' . get_string ( 'applydate', 'enrol_apply' ) . ''; echo ''; foreach ( $enrols as $enrol ) { - echo ''; - echo '' . format_string($enrol->course) . ''; - echo '' . $enrol->firstname . ' ' . $enrol->lastname . ''; - echo '' . $enrol->email . ''; - echo '' . date ( "Y-m-d", $enrol->timecreated ) . ''; + echo ''; + echo '' . format_string($enrol->course) . ''; + echo '' . $enrol->firstname . ' ' . $enrol->lastname . ''; + echo '' . $enrol->email . ''; + echo '' . date ( "Y-m-d", $enrol->timecreated ) . ''; } echo ''; echo '

  

'; diff --git a/settings.php b/settings.php index de61af9..ed85bbb 100644 --- a/settings.php +++ b/settings.php @@ -1,7 +1,7 @@ fulltree) { $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_configcheckbox('enrol_apply/sendmailtoteacher', get_string('sendmailtoteacher', 'enrol_apply'), '', 0)); + $settings->add(new admin_setting_configcheckbox('enrol_apply/sendmailtoteacher', get_string('sendmailtoteacher', 'enrol_apply'), '', 0)); $settings->add(new admin_setting_configcheckbox('enrol_apply/sendmailtomanager', get_string('sendmailtomanager', 'enrol_apply'), '', 0)); //--- enrol instance defaults ---------------------------------------------------------------------------- diff --git a/unenrolself.php b/unenrolself.php index 942014c..cf92998 100644 --- a/unenrolself.php +++ b/unenrolself.php @@ -49,11 +49,11 @@ $PAGE->set_title($plugin->get_instance_name($instance)); if ($confirm and confirm_sesskey()) { $plugin->unenrol_user($instance, $USER->id); - - // Deprecated fixed by Shiro + + // Deprecated fixed by Shiro //add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //TODO: there should be userid somewhere! - $context = context_course::instance($course->id); - \core\event\user_enrolment_deleted::delete(array('context' => $context))->trigger(); + $context = context_course::instance($course->id); + \core\event\user_enrolment_deleted::delete(array('context' => $context))->trigger(); redirect(new moodle_url('/index.php')); } diff --git a/unenroluser.php b/unenroluser.php index 9d423e4..dd2f7f1 100644 --- a/unenroluser.php +++ b/unenroluser.php @@ -1,7 +1,7 @@ $ue->enrolid, 'contextcourse' => CONTEXT_COURSE); $course = $DB->get_record_sql($sql, $params, MUST_EXIST); diff --git a/version.php b/version.php index 9d68c8b..373640b 100644 --- a/version.php +++ b/version.php @@ -1,7 +1,7 @@ version = 2016042201; From 9bf08acb8e1f686291086e4d965d8352392c67c1 Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Tue, 12 Apr 2016 12:10:43 +0200 Subject: [PATCH 02/28] Refactor: combine manage.php and apply.php to manage.php, rename locallib.php to apply_form.php and containing class from enrol_apply_enrol_form to enrol_apply_apply_form refactor code in manage.php --- apply.php | 112 -------------------------- locallib.php => apply_form.php | 2 +- lib.php | 34 ++++---- manage.php | 138 +++++++++++++++++++++++++-------- selectlib.php | 2 +- unenroluser.php | 1 - 6 files changed, 126 insertions(+), 163 deletions(-) delete mode 100644 apply.php rename locallib.php => apply_form.php (99%) diff --git a/apply.php b/apply.php deleted file mode 100644 index ba13992..0000000 --- a/apply.php +++ /dev/null @@ -1,112 +0,0 @@ -dirroot.'/enrol/renderer.php'); -require_once($CFG->dirroot.'/enrol/locallib.php'); -require_once($CFG->dirroot.'/lib/outputcomponents.php'); -require_once ('lib.php'); - -$site = get_site (); -$systemcontext = context_system::instance(); - -$id = required_param ( 'id', PARAM_INT ); // course id -$course = $DB->get_record ( 'course', array ('id' => $id ), '*', MUST_EXIST ); -$context = context_course::instance($course->id, MUST_EXIST); - -$enrolid = optional_param('enrolid', 0, PARAM_INT); - -require_login ( $course ); -require_capability ( 'moodle/course:enrolreview', $context ); - -$PAGE->set_url ( '/enrol/apply.php', array ('id' => $course->id ) ); -//$PAGE->set_context($systemcontext); -$PAGE->set_pagelayout ( 'admin' ); -$PAGE->set_heading ( $course->fullname ); - -$PAGE->navbar->add ( get_string ( 'confirmusers', 'enrol_apply' ) ); -$PAGE->set_title ( "$site->shortname: " . get_string ( 'confirmusers', 'enrol_apply' ) ); - -$userenrolments = optional_param_array('userenrolments', null, PARAM_INT); -if ($userenrolments != null) { - if ($_POST ['type'] == 'confirm') { - confirmEnrolment($userenrolments); - } elseif ($_POST ['type'] == 'wait') { - waitEnrolment ($userenrolments); - } elseif ($_POST ['type'] == 'cancel') { - cancelEnrolment($userenrolments); - } - redirect ( "$CFG->wwwroot/enrol/apply/apply.php?id=" . $id . "&enrolid=" . $enrolid ); -} - -$enrols = getAllEnrolment ($enrolid); -$applicationinfo = $DB->get_records_sql(' - SELECT userenrolmentid, comment - FROM {enrol_apply_applicationinfo} - WHERE userenrolmentid IN ( - SELECT id - FROM {user_enrolments} - WHERE enrolid = ?)', array($enrolid)); - -echo $OUTPUT->header (); -echo $OUTPUT->heading ( get_string ( 'confirmusers', 'enrol_apply' ) ); -echo get_string('confirmusers_desc', 'enrol_apply'); -echo '
'; -echo ''; -echo ''; -echo ''; -echo ''; -echo ''; -echo ''; -echo ''; -echo ''; -echo ''; -echo ''; -foreach ( $enrols as $enrol ) { - $picture = get_user_picture($enrol->userid); - if ($enrol->status == 2) { - echo ''; - } else { - echo ''; - } - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; -} -echo '
 ' . get_string ( 'coursename', 'enrol_apply' ) . ' ' . get_string ( 'applyuser', 'enrol_apply' ) . '' . get_string ( 'applyusermail', 'enrol_apply' ) . '' . get_string ( 'applydate', 'enrol_apply' ) . '' . get_string ( 'comment', 'enrol_apply' ) . '
' . format_string($enrol->course) . '' . $OUTPUT->render($picture) . ''.$enrol->firstname . ' ' . $enrol->lastname.'' . $enrol->email . '' . date ( "Y-m-d", $enrol->timecreated ) . '' . htmlspecialchars($applicationinfo[$enrol->id]->comment) . '
'; -echo '

'; -echo ''; -echo ''; -echo ''; -echo '

'; -echo '
'; -echo ''; -echo $OUTPUT->footer (); - - -function get_user_picture($userid){ - global $DB; - - $extrafields[] = 'lastaccess'; - $ufields = user_picture::fields('u', $extrafields); - $sql = "SELECT DISTINCT $ufields FROM {user} u where u.id=$userid"; - - $user = $DB->get_record_sql($sql); - return new user_picture($user); -} \ No newline at end of file diff --git a/locallib.php b/apply_form.php similarity index 99% rename from locallib.php rename to apply_form.php index 4ee596a..228b7a9 100644 --- a/locallib.php +++ b/apply_form.php @@ -23,7 +23,7 @@ defined('MOODLE_INTERNAL') || die(); require_once("$CFG->libdir/formslib.php"); -class enrol_apply_enrol_form extends moodleform { +class enrol_apply_apply_form extends moodleform { protected $instance; /** diff --git a/lib.php b/lib.php index aa27236..7f44c01 100644 --- a/lib.php +++ b/lib.php @@ -22,17 +22,22 @@ class enrol_apply_plugin extends enrol_plugin { } public function allow_unenrol(stdClass $instance) { - // users with unenrol cap may unenrol other users manually manually + // Users with unenrol cap may unenrol other users manually. return true; } + /** + * Returns link to page which may be used to add new instance of enrolment plugin in course. + * Multiple instances supported. + * @param int $courseid + * @return moodle_url page url + */ public function get_newinstance_link($courseid) { $context = context_course::instance($courseid, MUST_EXIST); if (!has_capability('moodle/course:enrolconfig', $context) or !has_capability('enrol/apply:config', $context)) { return NULL; } - // multiple instances supported - different roles with different password return new moodle_url('/enrol/apply/edit.php', array('courseid'=>$courseid)); } @@ -44,18 +49,16 @@ class enrol_apply_plugin extends enrol_plugin { return null; } if ($DB->record_exists('user_enrolments', array('userid'=>$USER->id, 'enrolid'=>$instance->id))) { - //TODO: maybe we should tell them they are already enrolled, but can not access the course - //return null; return $OUTPUT->notification(get_string('notification', 'enrol_apply'), 'notifysuccess'); } - require_once("$CFG->dirroot/enrol/apply/locallib.php"); + require_once("$CFG->dirroot/enrol/apply/apply_form.php"); - $form = new enrol_apply_enrol_form(NULL, $instance); + $form = new enrol_apply_apply_form(NULL, $instance); - $instanceid = optional_param('instance', 0, PARAM_INT); - if ($instance->id == $instanceid) { - if ($data = $form->get_data()) { + if ($data = $form->get_data()) { + // Only process when form submission is for this instance (multi instance support). + if ($data->instance == $instance->id) { $userInfo = $data; $applydescription = $userInfo->applydescription; unset($userInfo->applydescription); @@ -124,13 +127,10 @@ class enrol_apply_plugin extends enrol_plugin { redirect("$CFG->wwwroot/course/view.php?id=$instance->courseid"); } } - //exit; - ob_start(); - $form->display(); - $output = ob_get_clean(); - return $OUTPUT->box($output); + $output = $form->render(); + return $OUTPUT->box($output); } public function get_action_icons(stdClass $instance) { @@ -149,7 +149,7 @@ class enrol_apply_plugin extends enrol_plugin { } if (has_capability('enrol/apply:manage', $context)) { - $managelink = new moodle_url("/enrol/apply/apply.php", array('id'=>$_GET['id'],'enrolid'=>$instance->id)); + $managelink = new moodle_url("/enrol/apply/manage.php", array('id'=>$instance->id)); $icons[] = $OUTPUT->action_icon($managelink, new pix_icon('i/users', get_string('confirmenrol', 'enrol_apply'), 'core', array('class'=>'iconsmall'))); } @@ -253,7 +253,7 @@ function getAllEnrolment($id = null) { AND e.id = ?'; $userenrolments = $DB->get_records_sql($sql, array($id)); } else { - $sql = 'SELECT ue.id,ue.userid,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated + $sql = 'SELECT ue.id,ue.userid,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated,ue.status FROM {user_enrolments} ue LEFT JOIN {user} u ON ue.userid = u.id @@ -425,7 +425,7 @@ function sendConfirmMailToTeachers($instance,$info,$applydescription){ } } - $body .= '

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

'; + $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; diff --git a/manage.php b/manage.php index 5da4902..00a8d1a 100644 --- a/manage.php +++ b/manage.php @@ -9,54 +9,130 @@ * ************************************************************************* * ************************************************************************ */ -require ('../../config.php'); -require_once ('lib.php'); + +require_once ('../../config.php'); +require_once($CFG->dirroot.'/enrol/apply/lib.php'); + +$id = optional_param('id', null, PARAM_INT); +$userenrolments = optional_param_array('userenrolments', null, PARAM_INT); + require_login(); -require_capability('enrol/apply:manage', context_system::instance()); - -$site = get_site (); -$systemcontext = context_system::instance(); - -$PAGE->set_url ( '/enrol/manage.php'); -$PAGE->set_context($systemcontext); -$PAGE->set_pagelayout ( 'admin' ); -//$PAGE->set_heading ( $course->fullname ); - -$PAGE->navbar->add ( get_string ( 'confirmusers', 'enrol_apply' ) ); -$PAGE->set_title ( "$site->shortname: " . get_string ( 'confirmusers', 'enrol_apply' ) ); - -if (isset ( $_POST ['enrolid'] )) { - if ($_POST ['enrolid']) { - if ($_POST ['type'] == 'confirm') { - confirmEnrolment ( $_POST ['enrolid'] ); - } elseif ($_POST ['type'] == 'cancel') { - cancelEnrolment ( $_POST ['enrolid'] ); - } - redirect ( "$CFG->wwwroot/enrol/apply/manage.php" ); + +$manageurlparams = array(); +if ($id == null) { + $context = context_system::instance(); + require_capability('enrol/apply:manage', $context); + $pageheading = get_string('confirmusers', 'enrol_apply'); +} else { + $instance = $DB->get_record('enrol', array('id'=>$id, 'enrol'=>'apply'), '*', MUST_EXIST); + require_course_login($instance->courseid); + $course = get_course($instance->courseid); + $context = context_course::instance($course->id, MUST_EXIST); + require_capability('moodle/course:enrolreview', $context); + $manageurlparams['id'] = $instance->id; + $pageheading = $course->fullname; +} + +$manageurl = new moodle_url('/enrol/apply/manage.php', $manageurlparams); + +$PAGE->set_context($context); +$PAGE->set_url($manageurl); +$PAGE->set_pagelayout('admin'); +$PAGE->set_heading($pageheading); +$PAGE->navbar->add(get_string('confirmusers', 'enrol_apply')); +$PAGE->set_title(get_string('confirmusers', 'enrol_apply')); + +if ($userenrolments != null) { + $action = required_param('type', PARAM_TEXT); + switch ($action) { + case 'confirm': + confirmEnrolment($userenrolments); + break; + case 'wait': + waitEnrolment ($userenrolments); + break; + case 'cancel': + cancelEnrolment($userenrolments); + break; + default: + # code... + break; } + redirect($manageurl); +} + +$enrols = getAllEnrolment($id); +if ($id == null) { + $applicationinfo = $DB->get_records_sql(' + SELECT userenrolmentid, comment + FROM {enrol_apply_applicationinfo} + WHERE userenrolmentid IN ( + SELECT id + FROM {user_enrolments} + WHERE enrolid IN ( + SELECT id + FROM {enrol} + WHERE enrol = ?))', array('apply')); +} else { + $applicationinfo = $DB->get_records_sql(' + SELECT userenrolmentid, comment + FROM {enrol_apply_applicationinfo} + WHERE userenrolmentid IN ( + SELECT id + FROM {user_enrolments} + WHERE enrolid = ?)', array($instance->id)); } -$enrols = getAllEnrolment(); echo $OUTPUT->header (); echo $OUTPUT->heading ( get_string ( 'confirmusers', 'enrol_apply' ) ); -echo '
'; +echo get_string('confirmusers_desc', 'enrol_apply'); +echo ''; echo ''; echo ''; echo ''; echo ''; +echo ''; echo ''; echo ''; echo ''; +echo ''; echo ''; foreach ( $enrols as $enrol ) { - echo ''; + $picture = get_user_picture($enrol->userid); + if ($enrol->status == 2) { + echo ''; + } else { + echo ''; + } + echo ''; echo ''; - echo ''; + echo ''; + echo ''; echo ''; - echo ''; + echo ''; + echo ''; + echo ''; } echo '
 ' . get_string ( 'coursename', 'enrol_apply' ) . ' ' . get_string ( 'applyuser', 'enrol_apply' ) . '' . get_string ( 'applyusermail', 'enrol_apply' ) . '' . get_string ( 'applydate', 'enrol_apply' ) . '' . get_string ( 'comment', 'enrol_apply' ) . '
' . format_string($enrol->course) . '' . $enrol->firstname . ' ' . $enrol->lastname . '' . $OUTPUT->render($picture) . ''.$enrol->firstname . ' ' . $enrol->lastname.'' . $enrol->email . '' . date ( "Y-m-d", $enrol->timecreated ) . '
' . date ( "Y-m-d", $enrol->timecreated ) . '' . htmlspecialchars($applicationinfo[$enrol->id]->comment) . '
'; -echo '

  

'; +echo '

'; +echo ''; +echo ''; +echo ''; +echo '

'; echo '
'; -echo ''; -echo $OUTPUT->footer (); \ No newline at end of file +echo ''; +echo $OUTPUT->footer (); + +function get_user_picture($userid){ + global $DB; + + $extrafields[] = 'lastaccess'; + $ufields = user_picture::fields('u', $extrafields); + $sql = "SELECT DISTINCT $ufields FROM {user} u where u.id=$userid"; + + $user = $DB->get_record_sql($sql); + return new user_picture($user); +} \ No newline at end of file diff --git a/selectlib.php b/selectlib.php index f49c143..f162cab 100644 --- a/selectlib.php +++ b/selectlib.php @@ -149,7 +149,7 @@ class enrol_apply_current_participant extends user_selector_base { protected function get_options() { $options = parent::get_options(); $options['enrolid'] = $this->enrolid; - $options['file'] = 'enrol/apply/locallib.php'; + $options['file'] = 'enrol/apply/apply_form.php'; return $options; } } diff --git a/unenroluser.php b/unenroluser.php index dd2f7f1..f2b1912 100644 --- a/unenroluser.php +++ b/unenroluser.php @@ -19,7 +19,6 @@ */ require('../../config.php'); -require_once("$CFG->dirroot/enrol/locallib.php"); require_once("$CFG->dirroot/enrol/renderer.php"); $ueid = required_param('ue', PARAM_INT); // user enrolment id From a01b669a5f024efee8509595a920ce132fb6639a Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Tue, 12 Apr 2016 16:52:03 +0200 Subject: [PATCH 03/28] Use table_sql for manage table generation. --- lib.php | 30 ----------------- manage.php | 87 ++++++++++++++++-------------------------------- manage_table.php | 86 +++++++++++++++++++++++++++++++++++++++++++++++ style.css | 3 ++ 4 files changed, 117 insertions(+), 89 deletions(-) create mode 100644 manage_table.php create mode 100644 style.css diff --git a/lib.php b/lib.php index 7f44c01..3acf6f8 100644 --- a/lib.php +++ b/lib.php @@ -238,36 +238,6 @@ class enrol_apply_plugin extends enrol_plugin { } } -function getAllEnrolment($id = null) { - global $DB; - if ($id) { - $sql = 'SELECT ue.userid,ue.id,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated,ue.status - FROM {course} c - JOIN {enrol} e - ON e.courseid = c.id - JOIN {user_enrolments} ue - ON ue.enrolid = e.id - JOIN {user} u - ON ue.userid = u.id - WHERE ue.status != 0 - AND e.id = ?'; - $userenrolments = $DB->get_records_sql($sql, array($id)); - } else { - $sql = 'SELECT ue.id,ue.userid,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated,ue.status - FROM {user_enrolments} ue - LEFT JOIN {user} u - ON ue.userid = u.id - LEFT JOIN {enrol} e - ON ue.enrolid = e.id - LEFT JOIN {course} c - ON e.courseid = c.id - WHERE ue.status != 0 - AND e.enrol = ?'; - $userenrolments = $DB->get_records_sql($sql, array('apply')); - } - return $userenrolments; -} - function confirmEnrolment($enrols){ global $DB; global $CFG; diff --git a/manage.php b/manage.php index 00a8d1a..2995525 100644 --- a/manage.php +++ b/manage.php @@ -12,6 +12,7 @@ require_once ('../../config.php'); require_once($CFG->dirroot.'/enrol/apply/lib.php'); +require_once($CFG->dirroot.'/enrol/apply/manage_table.php'); $id = optional_param('id', null, PARAM_INT); $userenrolments = optional_param_array('userenrolments', null, PARAM_INT); @@ -41,6 +42,7 @@ $PAGE->set_pagelayout('admin'); $PAGE->set_heading($pageheading); $PAGE->navbar->add(get_string('confirmusers', 'enrol_apply')); $PAGE->set_title(get_string('confirmusers', 'enrol_apply')); +$PAGE->requires->css('/enrol/apply/style.css'); if ($userenrolments != null) { $action = required_param('type', PARAM_TEXT); @@ -61,59 +63,37 @@ if ($userenrolments != null) { redirect($manageurl); } -$enrols = getAllEnrolment($id); -if ($id == null) { - $applicationinfo = $DB->get_records_sql(' - SELECT userenrolmentid, comment - FROM {enrol_apply_applicationinfo} - WHERE userenrolmentid IN ( - SELECT id - FROM {user_enrolments} - WHERE enrolid IN ( - SELECT id - FROM {enrol} - WHERE enrol = ?))', array('apply')); -} else { - $applicationinfo = $DB->get_records_sql(' - SELECT userenrolmentid, comment - FROM {enrol_apply_applicationinfo} - WHERE userenrolmentid IN ( - SELECT id - FROM {user_enrolments} - WHERE enrolid = ?)', array($instance->id)); -} - echo $OUTPUT->header (); echo $OUTPUT->heading ( get_string ( 'confirmusers', 'enrol_apply' ) ); echo get_string('confirmusers_desc', 'enrol_apply'); + +$table = new enrol_apply_manage_table($id); +$table->define_baseurl($manageurl); +$columns = array( + 'checkboxcolumn', + 'course', + 'fullname', // Magic happens here: The column heading will automatically be set. + 'email', + 'applydate', + 'applycomment'); +$headers = array( + '', + get_string('course'), + 'fullname', // Magic happens here: The column heading will automatically be set due to column name 'fullname'. + get_string('email'), + get_string('applydate', 'enrol_apply'), + get_string('comment', 'enrol_apply')); +$table->define_columns($columns); +$table->define_headers($headers); + +$table->sortable(true, 'id'); + + echo '
'; echo ''; -echo ''; -echo ''; -echo ''; -echo ''; -echo ''; -echo ''; -echo ''; -echo ''; -echo ''; -foreach ( $enrols as $enrol ) { - $picture = get_user_picture($enrol->userid); - if ($enrol->status == 2) { - echo ''; - } else { - echo ''; - } - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; -} -echo '
 ' . get_string ( 'coursename', 'enrol_apply' ) . ' ' . get_string ( 'applyuser', 'enrol_apply' ) . '' . get_string ( 'applyusermail', 'enrol_apply' ) . '' . get_string ( 'applydate', 'enrol_apply' ) . '' . get_string ( 'comment', 'enrol_apply' ) . '
' . format_string($enrol->course) . '' . $OUTPUT->render($picture) . ''.$enrol->firstname . ' ' . $enrol->lastname.'' . $enrol->email . '' . date ( "Y-m-d", $enrol->timecreated ) . '' . htmlspecialchars($applicationinfo[$enrol->id]->comment) . '
'; + +$table->out(50, true); + echo '

'; echo ''; echo ''; @@ -125,14 +105,3 @@ echo ''; echo $OUTPUT->footer (); - -function get_user_picture($userid){ - global $DB; - - $extrafields[] = 'lastaccess'; - $ufields = user_picture::fields('u', $extrafields); - $sql = "SELECT DISTINCT $ufields FROM {user} u where u.id=$userid"; - - $user = $DB->get_record_sql($sql); - return new user_picture($user); -} \ No newline at end of file diff --git a/manage_table.php b/manage_table.php new file mode 100644 index 0000000..f0601a5 --- /dev/null +++ b/manage_table.php @@ -0,0 +1,86 @@ +. + +/** + * + * @package enrol_apply + * @copyright 2016 Johannes Burk + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * + */ + +defined('MOODLE_INTERNAL') || die(); + +require_once($CFG->libdir . '/tablelib.php'); + +class enrol_apply_manage_table extends table_sql { + + public $is_collapsible = false; + + public function __construct($enrolid = null) { + parent::__construct('enrol_apply_manage_table'); + + global $DB; + + $sqlwhere = 'ue.status != 0'; + $sqlparams = array(); + if ($enrolid != null) { + $sqlwhere .= " AND e.id = :enrolid"; + $sqlparams['enrolid'] = $enrolid; + } else { + $sqlwhere = "e.enrol = :enrol"; + $sqlparams['enrol'] = 'apply'; + } + + $this->set_sql( + 'ue.id AS userenrolmentid, ue.userid, ue.status AS enrolstatus, ue.timecreated AS applydate, ai.comment AS applycomment, u.*, c.fullname as course', + "{user_enrolments} AS ue + LEFT JOIN {enrol_apply_applicationinfo} AS ai ON ai.userenrolmentid = ue.id + JOIN {user} AS u ON u.id = ue.userid + JOIN {enrol} AS e ON e.id = ue.enrolid + JOIN {course} AS c ON c.id = e.courseid", + $sqlwhere, + $sqlparams); + } + + /** + * Get any extra classes names to add to this row in the HTML. + * @param $row array the data for this row. Note (Johannes): this is actually an object with all sql columns. + * @return string added to the class="" attribute of the tr. + */ + function get_row_class($row) { + if ($row->enrolstatus == 2) { + return 'enrol_apply_waitinglist_highlight'; + } + return ''; + } + + public function col_checkboxcolumn($row) { + return html_writer::checkbox('userenrolments[]', $row->userenrolmentid, false); + } + + public function col_fullname($row) { + // $row contains all user fields, see sql query. + global $OUTPUT; + $col = $OUTPUT->user_picture($row, array('popup'=>true)); + $col .= fullname($row); + return $col; + } + + public function col_applydate($row) { + return date("Y-m-d", $row->applydate); + } +} diff --git a/style.css b/style.css new file mode 100644 index 0000000..05b7433 --- /dev/null +++ b/style.css @@ -0,0 +1,3 @@ +.enrol_apply_waitinglist_highlight { + border-left: 6px solid grey; +} From d2f13478127b304a4a0d5d366bc12513a555ebbf Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Tue, 12 Apr 2016 17:21:33 +0200 Subject: [PATCH 04/28] Use html_writer for HTML generation --- manage.php | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/manage.php b/manage.php index 2995525..2373cb1 100644 --- a/manage.php +++ b/manage.php @@ -89,19 +89,32 @@ $table->define_headers($headers); $table->sortable(true, 'id'); -echo ''; -echo ''; +echo html_writer::start_tag('form', array('id' => 'enrol_apply_manage_form', 'method' => 'post', 'action' => $manageurl->out())); +echo html_writer::empty_tag('input', array('type' => 'hidden', 'id' => 'type', 'name' => 'type', 'value' => 'confirm')); $table->out(50, true); -echo '

'; -echo ''; -echo ''; -echo ''; -echo '

'; -echo '
'; -echo ''; +echo html_writer::start_tag('p', array('align' => 'center')); +echo html_writer::empty_tag('input', array( + 'type' => 'button', + 'onclick' => 'doSubmit("confirm");', + 'value' => get_string('btnconfirm', 'enrol_apply'))); +echo html_writer::empty_tag('input', array( + 'type' => 'button', + 'onclick' => 'doSubmit("wait");', + 'value' => get_string('btnwait', 'enrol_apply'))); +echo html_writer::empty_tag('input', array( + 'type' => 'button', + 'onclick' => 'doSubmit("cancel");', + 'value' => get_string('btncancel', 'enrol_apply'))); +echo html_writer::end_tag('p'); +echo html_writer::end_tag('form'); + +$js = " + function doSubmit(type){ + document.getElementById('type').value=type; + document.getElementById('enrol_apply_manage_form').submit(); + }"; +echo html_writer::tag('script', $js, array('type' => 'text/javascript')); + echo $OUTPUT->footer (); From 39dc5a568cfbcecafb7cd12dd41d3fd1bf2dac4c Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Tue, 12 Apr 2016 17:39:27 +0200 Subject: [PATCH 05/28] Move output code to renderer --- manage.php | 55 ++------------------------------ renderer.php | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 52 deletions(-) create mode 100644 renderer.php diff --git a/manage.php b/manage.php index 2373cb1..eab4cb7 100644 --- a/manage.php +++ b/manage.php @@ -13,6 +13,7 @@ require_once ('../../config.php'); require_once($CFG->dirroot.'/enrol/apply/lib.php'); require_once($CFG->dirroot.'/enrol/apply/manage_table.php'); +require_once($CFG->dirroot.'/enrol/apply/renderer.php'); $id = optional_param('id', null, PARAM_INT); $userenrolments = optional_param_array('userenrolments', null, PARAM_INT); @@ -63,58 +64,8 @@ if ($userenrolments != null) { redirect($manageurl); } -echo $OUTPUT->header (); -echo $OUTPUT->heading ( get_string ( 'confirmusers', 'enrol_apply' ) ); -echo get_string('confirmusers_desc', 'enrol_apply'); - $table = new enrol_apply_manage_table($id); $table->define_baseurl($manageurl); -$columns = array( - 'checkboxcolumn', - 'course', - 'fullname', // Magic happens here: The column heading will automatically be set. - 'email', - 'applydate', - 'applycomment'); -$headers = array( - '', - get_string('course'), - 'fullname', // Magic happens here: The column heading will automatically be set due to column name 'fullname'. - get_string('email'), - get_string('applydate', 'enrol_apply'), - get_string('comment', 'enrol_apply')); -$table->define_columns($columns); -$table->define_headers($headers); - -$table->sortable(true, 'id'); - - -echo html_writer::start_tag('form', array('id' => 'enrol_apply_manage_form', 'method' => 'post', 'action' => $manageurl->out())); -echo html_writer::empty_tag('input', array('type' => 'hidden', 'id' => 'type', 'name' => 'type', 'value' => 'confirm')); - -$table->out(50, true); - -echo html_writer::start_tag('p', array('align' => 'center')); -echo html_writer::empty_tag('input', array( - 'type' => 'button', - 'onclick' => 'doSubmit("confirm");', - 'value' => get_string('btnconfirm', 'enrol_apply'))); -echo html_writer::empty_tag('input', array( - 'type' => 'button', - 'onclick' => 'doSubmit("wait");', - 'value' => get_string('btnwait', 'enrol_apply'))); -echo html_writer::empty_tag('input', array( - 'type' => 'button', - 'onclick' => 'doSubmit("cancel");', - 'value' => get_string('btncancel', 'enrol_apply'))); -echo html_writer::end_tag('p'); -echo html_writer::end_tag('form'); - -$js = " - function doSubmit(type){ - document.getElementById('type').value=type; - document.getElementById('enrol_apply_manage_form').submit(); - }"; -echo html_writer::tag('script', $js, array('type' => 'text/javascript')); -echo $OUTPUT->footer (); +$renderer = $PAGE->get_renderer('enrol_apply'); +$renderer->manage_page($table, $manageurl); diff --git a/renderer.php b/renderer.php new file mode 100644 index 0000000..da1124d --- /dev/null +++ b/renderer.php @@ -0,0 +1,89 @@ +. + +/** + * + * @package enrol_apply + * @copyright 2015 sudile GbR (http://www.sudile.com) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @author Johannes Burk + */ + +defined('MOODLE_INTERNAL') || die(); + + +class enrol_apply_renderer extends plugin_renderer_base { + public function manage_page($table, $manageurl) { + echo $this->header(); + echo $this->heading(get_string('confirmusers', 'enrol_apply')); + echo get_string('confirmusers_desc', 'enrol_apply'); + $this->manage_form($table, $manageurl); + echo $this->footer(); + } + + public function manage_form($table, $manageurl) { + echo html_writer::start_tag('form', array('id' => 'enrol_apply_manage_form', 'method' => 'post', 'action' => $manageurl->out())); + echo html_writer::empty_tag('input', array('type' => 'hidden', 'id' => 'type', 'name' => 'type', 'value' => 'confirm')); + + $this->manage_table($table); + + echo html_writer::start_tag('p', array('align' => 'center')); + echo html_writer::empty_tag('input', array( + 'type' => 'button', + 'onclick' => 'doSubmit("confirm");', + 'value' => get_string('btnconfirm', 'enrol_apply'))); + echo html_writer::empty_tag('input', array( + 'type' => 'button', + 'onclick' => 'doSubmit("wait");', + 'value' => get_string('btnwait', 'enrol_apply'))); + echo html_writer::empty_tag('input', array( + 'type' => 'button', + 'onclick' => 'doSubmit("cancel");', + 'value' => get_string('btncancel', 'enrol_apply'))); + echo html_writer::end_tag('p'); + echo html_writer::end_tag('form'); + + $js = " + function doSubmit(type){ + document.getElementById('type').value=type; + document.getElementById('enrol_apply_manage_form').submit(); + }"; + echo html_writer::tag('script', $js, array('type' => 'text/javascript')); + } + + public function manage_table($table) { + $columns = array( + 'checkboxcolumn', + 'course', + 'fullname', // Magic happens here: The column heading will automatically be set. + 'email', + 'applydate', + 'applycomment'); + $headers = array( + '', + get_string('course'), + 'fullname', // Magic happens here: The column heading will automatically be set due to column name 'fullname'. + get_string('email'), + get_string('applydate', 'enrol_apply'), + get_string('comment', 'enrol_apply')); + $table->define_columns($columns); + $table->define_headers($headers); + + $table->sortable(true, 'id'); + + $table->out(50, true); + } +} \ No newline at end of file From 6c4261404dc0b0a728b0ca22f9c3b1ead436dfb7 Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Tue, 12 Apr 2016 18:46:37 +0200 Subject: [PATCH 06/28] Refactoring... --- apply_form.php | 14 ++------- edit.php | 2 ++ lib.php | 84 ++++++++------------------------------------------ 3 files changed, 16 insertions(+), 84 deletions(-) diff --git a/apply_form.php b/apply_form.php index 228b7a9..553d09c 100644 --- a/apply_form.php +++ b/apply_form.php @@ -72,18 +72,8 @@ class enrol_apply_apply_form extends moodleform { $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; - } + ($instance->customint1 == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false; + ($instance->customint2 == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false; if($show_standard_user_profile){ useredit_shared_definition($mform, $editoroptions, $filemanageroptions,$user); diff --git a/edit.php b/edit.php index d8b9626..e91733e 100644 --- a/edit.php +++ b/edit.php @@ -65,6 +65,8 @@ if ($mform->is_cancelled()) { 'status' =>$data->status, 'name' =>$data->name, 'roleid' =>$data->roleid, + 'customint1' =>$data->customint1, + 'customint2' =>$data->customint2, 'customint3' =>$data->customint3, 'customtext1' =>$data->customtext1); $plugin->add_instance($course, $fields); diff --git a/lib.php b/lib.php index 3acf6f8..3a4bdbe 100644 --- a/lib.php +++ b/lib.php @@ -64,46 +64,11 @@ class enrol_apply_plugin extends enrol_plugin { 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'"); - - $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); - //$res = $DB->update_record('user',$userInfo); - } - /*elseif($show_standard_user_profile && $show_extra_user_profile){ - profile_save_data($userInfo); - $res = $DB->update_record('user',$userInfo); - }*/ - - $enrol = enrol_get_plugin('self'); - $timestart = time(); - if ($instance->enrolperiod) { - $timeend = $timestart + $instance->enrolperiod; - } else { - $timeend = 0; - } - + $timestart = 0; + $timeend = 0; $roleid = $instance->roleid; - if(!$roleid){ - $role = $DB->get_record_sql("select * from ".$CFG->prefix."role where archetype='student' limit 1"); - $roleid = $role->id; - } - $this->enrol_user($instance, $USER->id, $roleid, $timestart, $timeend,1); + $this->enrol_user($instance, $USER->id, $roleid, $timestart, $timeend, ENROL_USER_SUSPENDED); $userenrolment = $DB->get_record('user_enrolments', array('userid' => $USER->id, 'enrolid' => $instance->id), 'id', MUST_EXIST); $applicationinfo = new stdClass(); $applicationinfo->userenrolmentid = $userenrolment->id; @@ -289,32 +254,29 @@ function cancelEnrolment($enrols){ function sendCancelMail($info){ global $DB; global $CFG; - $apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'"); $replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); - $body = $apply_setting['cancelmailcontent']->value; + $body = get_config('enrol_apply', 'cancelmailcontent'); $body = updateMailContent($body,$replace); $contact = core_user::get_support_user(); - email_to_user($info, $contact, $apply_setting['cancelmailsubject']->value, html_to_text($body), $body); + email_to_user($info, $contact, get_config('enrol_apply', 'cancelmailsubject'), html_to_text($body), $body); } function sendConfirmMail($info){ global $DB; global $CFG; - $apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'"); $replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); - $body = $apply_setting['confirmmailcontent']->value; + $body = get_config('enrol_apply', 'confirmmailcontent'); $body = updateMailContent($body,$replace); $contact = core_user::get_support_user(); - email_to_user($info, $contact, $apply_setting['confirmmailsubject']->value, html_to_text($body), $body); + email_to_user($info, $contact, get_config('enrol_apply', 'confirmmailsubject'), html_to_text($body), $body); } function sendWaitMail($info){ global $DB; global $CFG; //global $USER; - $apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'"); $replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); $body = get_config('enrol_apply', 'waitmailcontent'); @@ -332,20 +294,9 @@ function sendConfirmMailToTeachers($instance,$info,$applydescription){ $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; - } + ($instance->customint1 == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false; + ($instance->customint2 == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false; if($instance->customint3 == 1){ $course = get_course($courseid); @@ -410,22 +361,11 @@ function sendConfirmMailToManagers($instance,$info,$applydescription){ 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; - } + ($instance->customint1 == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false; + ($instance->customint2 == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false; - if($apply_setting['sendmailtomanager']->value == 1){ + if(get_config('enrol_apply', 'sendmailtomanager') == 1){ $course = get_course($courseid); $context = context_system::instance(); $managerType = $DB->get_record('role',array("shortname"=>"manager")); From 55d7a077092a0c833707868bbbcb8682d5762cba Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Thu, 26 May 2016 10:47:32 +0200 Subject: [PATCH 07/28] Refactor settings --- apply_form.php | 7 +-- db/upgrade.php | 16 +++++++ edit_form.php | 4 +- lang/en/enrol_apply.php | 23 +++++++-- lib.php | 14 ++---- settings.php | 102 ++++++++++++++++++++++++++++++---------- version.php | 2 +- 7 files changed, 122 insertions(+), 46 deletions(-) diff --git a/apply_form.php b/apply_form.php index 553d09c..77bc667 100644 --- a/apply_form.php +++ b/apply_form.php @@ -72,14 +72,11 @@ class enrol_apply_apply_form extends moodleform { $apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'"); - ($instance->customint1 == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false; - ($instance->customint2 == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false; - - if($show_standard_user_profile){ + if($instance->customint1){ useredit_shared_definition($mform, $editoroptions, $filemanageroptions,$user); } - if($show_extra_user_profile){ + if($instance->customint2){ profile_definition($mform, $user->id); } diff --git a/db/upgrade.php b/db/upgrade.php index 93b7df0..c402af8 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -51,6 +51,22 @@ function xmldb_enrol_apply_upgrade($oldversion) { upgrade_plugin_savepoint(true, 2016012801, 'enrol', 'apply'); } + if ($oldversion < 2016042202) { + // Invert settings for showing standard and extra user profile fields. + $enrolapply = enrol_get_plugin('apply'); + $showstandarduserprofile = $enrolapply->get_config('show_standard_user_profile') == 0 ? true : false; + $enrolapply->set_config('show_standard_user_profile', $showstandarduserprofile); + $showextrauserprofile = $enrolapply->get_config('show_extra_user_profile') == 0 ? true : false; + $enrolapply->set_config('show_extra_user_profile', $showextrauserprofile); + + $instances = $DB->get_records('enrol', array('enrol' => 'apply')); + foreach ($instances as $instance) { + $instance->customint1 = !$instance->customint1; + $instance->customint2 = !$instance->customint2; + $DB->update_record('enrol', $instance, true); + } + } + return true; } \ No newline at end of file diff --git a/edit_form.php b/edit_form.php index 07b7466..ed97deb 100644 --- a/edit_form.php +++ b/edit_form.php @@ -26,8 +26,8 @@ class enrol_self_edit_form extends moodleform { $mform->addElement('text', 'name', get_string('custominstancename', 'enrol')); $mform->setType('name', PARAM_TEXT); - $options = array(ENROL_INSTANCE_ENABLED => get_string('yes'), - ENROL_INSTANCE_DISABLED => get_string('no')); + $options = array(1 => get_string('yes'), + 0 => get_string('no')); $mform->addElement('select', 'status', get_string('status', 'enrol_apply'), $options); //$mform->addHelpButton('status', 'status', 'enrol_apply'); $mform->setDefault('status', $plugin->get_config('status')); diff --git a/lang/en/enrol_apply.php b/lang/en/enrol_apply.php index 371e691..d71d897 100644 --- a/lang/en/enrol_apply.php +++ b/lang/en/enrol_apply.php @@ -14,16 +14,32 @@ $string['enrolname'] = 'Course enrol confirmation'; $string['pluginname'] = 'Course enrol confirmation'; $string['pluginname_desc'] = 'With this plug-in users can apply to be enrolled in a course. A teacher or site manager will then have to approve the enrolment before the user gets enroled.'; +$string['confirmmail_heading'] = 'Confirmation email'; +$string['confirmmail_desc'] = ''; $string['confirmmailsubject'] = 'Confirmation email subject'; +$string['confirmmailsubject_desc'] = ''; $string['confirmmailcontent'] = 'Confirmation email content'; +$string['confirmmailcontent_desc'] = 'Please use the following special marks to replace email content with data from Moodle.
{firstname}:The first name of the user; {content}:The course name;{lastname}:The last name of the user;{username}:The users registration username'; + +$string['waitmail_heading'] = 'Waiting list email'; +$string['waitmail_desc'] = ''; $string['waitmailsubject'] = 'Waiting list mail subject'; +$string['waitmailsubject_desc'] = ''; $string['waitmailcontent'] = 'Waiting list mail content'; +$string['waitmailcontent_desc'] = 'Please use the following special marks to replace email content with data from Moodle.
{firstname}:The first name of the user; {content}:The course name;{lastname}:The last name of the user;{username}:The users registration username'; + +$string['cancelmail_heading'] = 'Cancelation email'; +$string['cancelmail_desc'] = ''; $string['cancelmailsubject'] = 'Cancelation email subject'; +$string['cancelmailsubject_desc'] = ''; $string['cancelmailcontent'] = 'Cancelation email content'; -$string['confirmmailcontent_desc'] = 'Please use the following special marks to replace email content with data from Moodle.
{firstname}:The first name of the user; {content}:The course name;{lastname}:The last name of the user;{username}:The users registration username'; -$string['waitmailcontent_desc'] = 'Please use the following special marks to replace email content with data from Moodle.
{firstname}:The first name of the user; {content}:The course name;{lastname}:The last name of the user;{username}:The users registration username'; $string['cancelmailcontent_desc'] = 'Please use the following special marks to replace email content with data from Moodle.
{firstname}:The first name of the user; {content}:The course name;{lastname}:The last name of the user;{username}:The users registration username'; +$string['notify_heading'] = 'Notification settings'; +$string['notify_desc'] = 'Define who gets notified about new enrolment applications.'; +$string['sendmailtoteacher'] = 'Send email notification to teachers'; +$string['sendmailtomanager'] = 'Send email notification to managers'; + $string['confirmusers'] = 'Enrol Confirm'; $string['confirmusers_desc'] = 'Users in gray colored rows are on the waiting list.'; @@ -49,8 +65,7 @@ $string['apply:unenrolself'] = 'Cancel self from the course'; $string['notification'] = 'Enrolment application successfully sent.

You will be informed by email when your enrolment has been confirmed.'; -$string['sendmailtoteacher'] = 'Send email notification to teachers'; -$string['sendmailtomanager'] = 'Send email notification to managers'; + $string['mailtoteacher_suject'] = 'New Enrolment request!'; $string['editdescription'] = 'Textarea description'; $string['comment'] = 'Comment'; diff --git a/lib.php b/lib.php index 3a4bdbe..f68076d 100644 --- a/lib.php +++ b/lib.php @@ -295,9 +295,6 @@ function sendConfirmMailToTeachers($instance,$info,$applydescription){ $courseid = $instance->courseid; $instanceid = $instance->id; - ($instance->customint1 == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false; - ($instance->customint2 == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false; - if($instance->customint3 == 1){ $course = get_course($courseid); $context = context_course::instance($courseid, MUST_EXIST); @@ -309,7 +306,7 @@ function sendConfirmMailToTeachers($instance,$info,$applydescription){ $body .= '

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

'; $body .= '

'. get_string('comment', 'enrol_apply') .': '.$applydescription.'

'; - if($show_standard_user_profile){ + if($instance->customint1){ $body .= '

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

'; $body .= '

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

'; $body .= '

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

'; @@ -337,7 +334,7 @@ function sendConfirmMailToTeachers($instance,$info,$applydescription){ $body .= '

'. get_string('address') .': '.$info->address.'

'; } - if($show_extra_user_profile){ + 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); @@ -362,9 +359,6 @@ function sendConfirmMailToManagers($instance,$info,$applydescription){ $courseid = $instance->courseid; - ($instance->customint1 == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false; - ($instance->customint2 == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false; - if(get_config('enrol_apply', 'sendmailtomanager') == 1){ $course = get_course($courseid); $context = context_system::instance(); @@ -375,7 +369,7 @@ function sendConfirmMailToManagers($instance,$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($show_standard_user_profile){ + if($instance->customint1){ $body .= '

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

'; $body .= '

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

'; $body .= '

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

'; @@ -403,7 +397,7 @@ function sendConfirmMailToManagers($instance,$info,$applydescription){ $body .= '

'. get_string('address') .': '.$info->address.'

'; } - if($show_extra_user_profile){ + 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); diff --git a/settings.php b/settings.php index ed85bbb..33a0836 100644 --- a/settings.php +++ b/settings.php @@ -13,48 +13,102 @@ defined('MOODLE_INTERNAL') || die(); if ($ADMIN->fulltree) { - //--- general settings ----------------------------------------------------------------------------------- $settings->add(new admin_setting_heading('enrol_apply_enrolname','',get_string('pluginname_desc', 'enrol_apply'))); - $settings->add(new admin_setting_configtext('enrol_apply/confirmmailsubject','',get_string('confirmmailsubject', 'enrol_apply'),null,PARAM_TEXT,60)); + // Confirm mail settings. + $settings->add(new admin_setting_heading( + 'enrol_apply_confirmmail', + get_string('confirmmail_heading', 'enrol_apply'), + get_string('confirmmail_desc', 'enrol_apply'))); + $settings->add(new admin_setting_configtext( + 'enrol_apply/confirmmailsubject', + get_string('confirmmailsubject', 'enrol_apply'), + get_string('confirmmailsubject_desc', 'enrol_apply'), + null, + PARAM_TEXT, + 60)); + $settings->add(new admin_setting_confightmleditor( + 'enrol_apply/confirmmailcontent', + get_string('confirmmailcontent', 'enrol_apply'), + get_string('confirmmailcontent_desc', 'enrol_apply'), + null, + PARAM_TEXT)); - $settings->add(new admin_setting_heading('enrol_apply_confirmmailcontent', '', get_string('confirmmailcontent_desc', 'enrol_apply'))); - $settings->add(new admin_setting_confightmleditor('enrol_apply/confirmmailcontent', get_string('confirmmailcontent', 'enrol_apply'),'utf-8','')); - - $settings->add(new admin_setting_configtext('enrol_apply/waitmailsubject','',get_string('waitmailsubject', 'enrol_apply'),null,PARAM_TEXT,60)); + // Wait mail settings. + $settings->add(new admin_setting_heading( + 'enrol_apply_waitmail', + get_string('waitmail_heading', 'enrol_apply'), + get_string('waitmail_desc', 'enrol_apply'))); + $settings->add(new admin_setting_configtext( + 'enrol_apply/waitmailsubject', + get_string('waitmailsubject', 'enrol_apply'), + get_string('waitmailsubject_desc', 'enrol_apply'), + null, + PARAM_TEXT, + 60)); + $settings->add(new admin_setting_confightmleditor( + 'enrol_apply/waitmailcontent', + get_string('waitmailcontent', 'enrol_apply'), + get_string('waitmailcontent_desc', 'enrol_apply'), + null, + PARAM_TEXT)); - $settings->add(new admin_setting_heading('enrol_apply_waitmailcontent', '', get_string('waitmailcontent_desc', 'enrol_apply'))); - $settings->add(new admin_setting_confightmleditor('enrol_apply/waitmailcontent', get_string('waitmailcontent', 'enrol_apply'),'utf-8','')); + // Cancel mail settings + $settings->add(new admin_setting_heading( + 'enrol_apply_cancelmail', + get_string('cancelmail_heading', 'enrol_apply'), + get_string('cancelmail_desc', 'enrol_apply'))); + $settings->add(new admin_setting_configtext( + 'enrol_apply/cancelmailsubject', + get_string('cancelmailsubject', 'enrol_apply'), + get_string('cancelmailsubject_desc', 'enrol_apply'), + null, + PARAM_TEXT, + 60)); + $settings->add(new admin_setting_confightmleditor( + 'enrol_apply/cancelmailcontent', + get_string('cancelmailcontent', 'enrol_apply'), + get_string('cancelmailcontent_desc', 'enrol_apply'), + null, + PARAM_TEXT)); - $settings->add(new admin_setting_configtext('enrol_apply/cancelmailsubject','',get_string('cancelmailsubject', 'enrol_apply'),null,PARAM_TEXT,60)); + // Notification settings. + $settings->add(new admin_setting_heading( + 'enrol_apply_notify', + get_string('notify_heading', 'enrol_apply'), + get_string('notify_desc', 'enrol_apply'))); + $settings->add(new admin_setting_configcheckbox( + 'enrol_apply/sendmailtoteacher', + get_string('sendmailtoteacher', 'enrol_apply'), + '', + 0)); + $settings->add(new admin_setting_configcheckbox( + 'enrol_apply/sendmailtomanager', + get_string('sendmailtomanager', 'enrol_apply'), + '', + 0)); - $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_configcheckbox('enrol_apply/sendmailtoteacher', 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', get_string('enrolinstancedefaults', 'admin'), get_string('enrolinstancedefaults_desc', 'admin'))); - + $settings->add(new admin_setting_configcheckbox('enrol_apply/defaultenrol', get_string('defaultenrol', 'enrol'), get_string('defaultenrol_desc', 'enrol'), 0)); - + $options = array(ENROL_INSTANCE_ENABLED => get_string('yes'), ENROL_INSTANCE_DISABLED => get_string('no')); $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')); + $options = array(1 => get_string('yes'), + 0 => 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)); + get_string('show_standard_user_profile', 'enrol_apply'), '', 1, $options)); - $options = array(ENROL_INSTANCE_ENABLED => get_string('yes'), - ENROL_INSTANCE_DISABLED => get_string('no')); + $options = array(1 => get_string('yes'), + 0 => 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)); + get_string('show_extra_user_profile', 'enrol_apply'), '', 1, $options)); if (!during_initial_install()) { $options = get_default_enrol_roles(context_system::instance()); diff --git a/version.php b/version.php index 373640b..46fca18 100644 --- a/version.php +++ b/version.php @@ -19,7 +19,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2016042201; +$plugin->version = 2016042202; $plugin->requires = 2011080100; $plugin->maturity = MATURITY_STABLE; $plugin->release = 'Enrolment upon approval plugin Version 3.0-d'; From 310a13e9573be2d93edf7b870b9f31dab1752a69 Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Thu, 26 May 2016 11:00:59 +0200 Subject: [PATCH 08/28] Remove unused capability 'apply:unenrolapply' --- db/access.php | 9 --------- lang/ca/enrol_apply.php | 1 - lang/de/enrol_apply.php | 1 - lang/en/enrol_apply.php | 1 - lang/es/enrol_apply.php | 1 - lang/it/enrol_apply.php | 1 - lang/pt_br/enrol_apply.php | 1 - lang/zh_cn/enrol_apply.php | 1 - 8 files changed, 16 deletions(-) diff --git a/db/access.php b/db/access.php index bb8818d..fc120ab 100644 --- a/db/access.php +++ b/db/access.php @@ -44,15 +44,6 @@ $capabilities = array( ) ), - //is this still necessary? - 'enrol/apply:unenrolapply' => array( - 'captype' => 'write', - 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( - 'student' => CAP_ALLOW, - ) - ), - 'enrol/apply:enrol' => array( 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, diff --git a/lang/ca/enrol_apply.php b/lang/ca/enrol_apply.php index 89a972b..7473bd5 100644 --- a/lang/ca/enrol_apply.php +++ b/lang/ca/enrol_apply.php @@ -37,7 +37,6 @@ $string['confirmenrol'] = 'Gestionar sol·licituds'; $string['apply:config'] = 'Configurar instàncies d\'Inscripció prèvia aprovació'; // Needs more insight $string['apply:manage'] = 'Gestionar la Inscripció prèvia aprovació'; // Needs more insight $string['apply:unenrol'] = 'Cancel·lar usuaris del curs'; // Needs more insight -$string['apply:unenrolapply'] = 'Cancel·lar-se a si mateix del curs'; // Needs more insight. Very ugly translation! $string['notification'] = 'Sol·licitud d\'inscripció enviada correctament.

Rebràs una notificació per correu electrònic un cop estigui confirmada la inscripció.'; diff --git a/lang/de/enrol_apply.php b/lang/de/enrol_apply.php index e2c331c..42fe5bf 100644 --- a/lang/de/enrol_apply.php +++ b/lang/de/enrol_apply.php @@ -42,7 +42,6 @@ $string['confirmenrol'] = 'Einschreibeanfragen bearbeiten'; $string['apply:config'] = 'Einschreibungsbelegstellen anlegen'; $string['apply:manage'] = 'Einschreibungsanfragen verwalten'; $string['apply:unenrol'] = 'Benutzer aus dem Kurs entfernen'; -$string['apply:unenrolapply'] = 'Sich selbst aus dem Kurs entfernen'; $string['notification'] = 'Einschreibungsantrag wurde erfolgreich gesendet..

Sie werden via Mail informiert, sobald Ihre Einschreibung bestätigt wurde.'; diff --git a/lang/en/enrol_apply.php b/lang/en/enrol_apply.php index d71d897..2fb9ed9 100644 --- a/lang/en/enrol_apply.php +++ b/lang/en/enrol_apply.php @@ -59,7 +59,6 @@ $string['apply:config'] = 'Configure apply enrol instances'; $string['apply:enrol'] = 'Enrol users'; $string['apply:manage'] = 'Manage apply enrolment'; $string['apply:unenrol'] = 'Cancel users from the course'; -$string['apply:unenrolapply'] = 'Cancel self from the course'; // is this necessary now? $string['apply:unenrolself'] = 'Cancel self from the course'; diff --git a/lang/es/enrol_apply.php b/lang/es/enrol_apply.php index bec4033..69d19f4 100644 --- a/lang/es/enrol_apply.php +++ b/lang/es/enrol_apply.php @@ -37,7 +37,6 @@ $string['confirmenrol'] = 'Gestionar solicitudes'; $string['apply:config'] = 'Configurar instancias de matrículas solicitadas'; // Needs more insight $string['apply:manage'] = 'Gestionar matrículas solicitadas'; // Needs more insight $string['apply:unenrol'] = 'Cancelar usuarios del curso'; // Needs more insight -$string['apply:unenrolapply'] = 'Cancelarse a si mismo del curso'; // Needs more insight. Very ugly translation! $string['notification'] = 'Solicitud de matriculación enviada correctamente.

Será notificado por correo electrónico en cuanto se confirme su matriculación.'; diff --git a/lang/it/enrol_apply.php b/lang/it/enrol_apply.php index 055dd51..744a71b 100644 --- a/lang/it/enrol_apply.php +++ b/lang/it/enrol_apply.php @@ -37,7 +37,6 @@ $string['confirmenrol'] = 'Gestisci l\'applicazione'; $string['apply:config'] = 'Configura le istanze del plugin'; $string['apply:manage'] = 'Gestisci le richieste di iscrizione'; $string['apply:unenrol'] = 'Cancella gli utenti dal corso'; -$string['apply:unenrolapply'] = 'Permetti all\'utente di disiscriversi dal corso'; // is this necessary now? $string['apply:unenrolself'] = 'Permetti all\'utente di disiscriversi dal corso'; $string['notification'] = 'Richiesta di iscrizione al corso correttamente inviata.

Verrai informato via email appena la tua richiesta di iscrizione viene confermata. Se vuoi iscriverti ad altri corsi, premi sul "catalogo dei corsi" sul top menu.'; diff --git a/lang/pt_br/enrol_apply.php b/lang/pt_br/enrol_apply.php index 145394c..b448761 100644 --- a/lang/pt_br/enrol_apply.php +++ b/lang/pt_br/enrol_apply.php @@ -37,7 +37,6 @@ $string['confirmenrol'] = 'Gerenciar solicitações'; $string['apply:config'] = 'Configurar instâncias de matrículas solicitadas'; // Needs more insight $string['apply:manage'] = 'Gerenciar matrículas solicitadas'; // Needs more insight $string['apply:unenrol'] = 'Cancelar usuários do curso'; // Needs more insight -$string['apply:unenrolapply'] = 'Cancelar minha matrícula do curso'; // Needs more insight. Very ugly translation! $string['notification'] = 'Solicitação de matrícula enviada com sucesso.

Você será notificado por e-mail quando a sua matrícula for confirmada.'; diff --git a/lang/zh_cn/enrol_apply.php b/lang/zh_cn/enrol_apply.php index 47cd24d..e5d837e 100644 --- a/lang/zh_cn/enrol_apply.php +++ b/lang/zh_cn/enrol_apply.php @@ -37,7 +37,6 @@ $string['confirmenrol'] = '管理申请'; $string['apply:config'] = '配置选课确认的实例'; $string['apply:manage'] = '管理选课申请'; $string['apply:unenrol'] = '从课程中取消用户的选课'; -$string['apply:unenrolapply'] = '从课程中取消自身的选课'; // is this necessary now? $string['apply:unenrolself'] = '从课程中取消自身的选课'; From efb639cee56f2d4751d1c33f77984c1238c1e336 Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Thu, 26 May 2016 11:24:04 +0200 Subject: [PATCH 09/28] Fix indention --- lib.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib.php b/lib.php index f68076d..3bc16d2 100644 --- a/lib.php +++ b/lib.php @@ -151,13 +151,13 @@ class enrol_apply_plugin extends enrol_plugin { /** - * Sets up navigation entries. - * - * @param stdClass $instancesnode - * @param stdClass $instance - * @return void - */ - public function add_course_navigation($instancesnode, stdClass $instance) { + * Sets up navigation entries. + * + * @param stdClass $instancesnode + * @param stdClass $instance + * @return void + */ + public function add_course_navigation($instancesnode, stdClass $instance) { if ($instance->enrol !== 'apply') { throw new coding_exception('Invalid enrol instance type!'); } From c89c845a0e6675ca2c62f198a0087dcf4ad54b54 Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Thu, 26 May 2016 16:45:42 +0200 Subject: [PATCH 10/28] Do not allow manual enrolment and unenrolment, remove corresponding code. --- enroluser.php | 187 ------------------------------------------------ lib.php | 19 ++--- selectlib.php | 155 --------------------------------------- unenroluser.php | 97 ------------------------- 4 files changed, 7 insertions(+), 451 deletions(-) delete mode 100644 enroluser.php delete mode 100644 selectlib.php delete mode 100644 unenroluser.php diff --git a/enroluser.php b/enroluser.php deleted file mode 100644 index 901f135..0000000 --- a/enroluser.php +++ /dev/null @@ -1,187 +0,0 @@ -dirroot.'/enrol/apply/selectlib.php'); - -$enrolid = required_param('enrolid', PARAM_INT); -$roleid = optional_param('roleid', -1, PARAM_INT); -$extendperiod = optional_param('extendperiod', 0, PARAM_INT); -$extendbase = optional_param('extendbase', 3, PARAM_INT); - -$instance = $DB->get_record('enrol', array('id'=>$enrolid, 'enrol'=>'apply'), '*', MUST_EXIST); -$course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST); -$context = context_course::instance($course->id, MUST_EXIST); - -require_login($course); -//require_capability('enrol/manual:enrol', $context); -//require_capability('enrol/manual:manage', $context); -//require_capability('enrol/manual:unenrol', $context); - -if ($roleid < 0) { - $roleid = $instance->roleid; -} -$roles = get_assignable_roles($context); -$roles = array('0'=>get_string('none')) + $roles; - -if (!isset($roles[$roleid])) { - // weird - security always first! - $roleid = 0; -} - -if (!$enrol_manual = enrol_get_plugin('apply')) { - throw new coding_exception('Can not instantiate enrol_manual'); -} - -$instancename = $enrol_manual->get_instance_name($instance); - -$PAGE->set_url('/enrol/apply/enroluser.php', array('enrolid'=>$instance->id)); -$PAGE->set_pagelayout('admin'); -$PAGE->set_title($enrol_manual->get_instance_name($instance)); -$PAGE->set_heading($course->fullname); -navigation_node::override_active_url(new moodle_url('/enrol/users.php', array('id'=>$course->id))); - -// Create the user selector objects. -$options = array('enrolid' => $enrolid); - -$potentialuserselector = new enrol_apply_potential_participant('addselect', $options); -$currentuserselector = new enrol_apply_current_participant('removeselect', $options); - -// Build the list of options for the enrolment period dropdown. -$unlimitedperiod = get_string('unlimited'); -$periodmenu = array(); -for ($i=1; $i<=365; $i++) { - $seconds = $i * 86400; - $periodmenu[$seconds] = get_string('numdays', '', $i); -} -// Work out the apropriate default setting. -if ($extendperiod) { - $defaultperiod = $extendperiod; -} else { - $defaultperiod = $instance->enrolperiod; -} - -// Build the list of options for the starting from dropdown. -$timeformat = get_string('strftimedatefullshort'); -$today = time(); -$today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0); - -// enrolment start -$basemenu = array(); -if ($course->startdate > 0) { - $basemenu[2] = get_string('coursestart') . ' (' . userdate($course->startdate, $timeformat) . ')'; -} -$basemenu[3] = get_string('today') . ' (' . userdate($today, $timeformat) . ')' ; - -// process add and removes -if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) { - $userstoassign = $potentialuserselector->get_selected_users(); - if (!empty($userstoassign)) { - foreach($userstoassign as $adduser) { - switch($extendbase) { - case 2: - $timestart = $course->startdate; - break; - case 3: - default: - $timestart = $today; - break; - } - - if ($extendperiod <= 0) { - $timeend = 0; - } else { - $timeend = $timestart + $extendperiod; - } - //echo "
";print_r($instance);exit();
-            $enrol_manual->enrol_user($instance, $adduser->id, $roleid, $timestart, $timeend);
-
-            // Deprecated fixed by Shiro 
-            //add_to_log($course->id, 'course', 'enrol', '../enrol/users.php?id='.$course->id, $course->id); //there should be userid somewhere!
-            $context = context_course::instance($course->id);
-            \core\event\user_enrolment_created::create(array('context' => $context))->trigger();
-        }
-
-        $potentialuserselector->invalidate_selected_users();
-        $currentuserselector->invalidate_selected_users();
-
-        //TODO: log
-    }
-}
-
-// Process incoming role unassignments
-if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
-    $userstounassign = $currentuserselector->get_selected_users();
-    if (!empty($userstounassign)) {
-        foreach($userstounassign as $removeuser) {
-            $enrol_manual->unenrol_user($instance, $removeuser->id);
-
-            // Deprecated fixed by Shiro 
-            //add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //there should be userid somewhere!
-            $context = context_course::instance($course->id);
-            \core\event\user_enrolment_deleted::delete(array('context' => $context))->trigger();
-        }
-
-        $potentialuserselector->invalidate_selected_users();
-        $currentuserselector->invalidate_selected_users();
-
-        //TODO: log
-    }
-}
-
-
-echo $OUTPUT->header();
-echo $OUTPUT->heading($instancename);
-
-?>
-
- - - - - - - - -
-

- display() ?> -
-
-
- -
- -


-

- -


-

- -


-

- -
-
- -
- -
-
-

- display() ?> -
-
-footer(); diff --git a/lib.php b/lib.php index 3bc16d2..7a9196f 100644 --- a/lib.php +++ b/lib.php @@ -118,11 +118,6 @@ class enrol_apply_plugin extends enrol_plugin { $icons[] = $OUTPUT->action_icon($managelink, new pix_icon('i/users', get_string('confirmenrol', 'enrol_apply'), 'core', array('class'=>'iconsmall'))); } - if (has_capability("enrol/apply:enrol", $context)) { - $enrollink = new moodle_url("/enrol/apply/enroluser.php", array('enrolid'=>$instance->id)); - $icons[] = $OUTPUT->action_icon($enrollink, new pix_icon('t/enrolusers', get_string('enrolusers', 'enrol_apply'), 'core', array('class'=>'iconsmall'))); - } - return $icons; } @@ -175,13 +170,13 @@ class enrol_apply_plugin extends enrol_plugin { $instance = $ue->enrolmentinstance; $params = $manager->get_moodlepage()->url->params(); $params['ue'] = $ue->id; - if ($this->allow_unenrol($instance) && has_capability("enrol/apply:unenrol", $context)) { - $url = new moodle_url('/enrol/apply/unenroluser.php', $params); - $actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, array('class'=>'unenrollink', 'rel'=>$ue->id)); - } - if ($this->allow_manage($instance) && has_capability("enrol/apply:manage", $context)) { - $url = new moodle_url('/enrol/apply/editenrolment.php', $params); - $actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, array('class'=>'editenrollink', 'rel'=>$ue->id)); + if ($this->allow_unenrol_user($instance, $ue) && has_capability("enrol/apply:unenrol", $context)) { + $url = new moodle_url('/enrol/unenroluser.php', $params); + $actions[] = new user_enrolment_action( + new pix_icon('t/delete', ''), + get_string('unenrol', 'enrol'), + $url, + array('class' => 'unenrollink', 'rel' => $ue->id)); } return $actions; } diff --git a/selectlib.php b/selectlib.php deleted file mode 100644 index f162cab..0000000 --- a/selectlib.php +++ /dev/null @@ -1,155 +0,0 @@ -. - -/** - * Auxiliary manual user enrolment lib, the main purpose is to lower memory requirements... - * - * @package enrol - * @subpackage manual - * @copyright 2010 Petr Skoda {@link http://skodak.org} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -require_once($CFG->dirroot . '/user/selector/lib.php'); - -/** - * Enrol candidates - */ -class enrol_apply_potential_participant extends user_selector_base { - protected $enrolid; - - public function __construct($name, $options) { - $this->enrolid = $options['enrolid']; - parent::__construct($name, $options); - } - - /** - * Candidate users - * @param $search - * @return array - */ - public function find_users($search) { - global $DB; - //by default wherecondition retrieves all users except the deleted, not confirmed and guest - list($wherecondition, $params) = $this->search_sql($search, 'u'); - $params['enrolid'] = $this->enrolid; - - $fields = 'SELECT ' . $this->required_fields_sql('u'); - $countfields = 'SELECT COUNT(1)'; - - $sql = " FROM {user} u - WHERE $wherecondition - AND u.id NOT IN (SELECT ue.userid - FROM {user_enrolments} ue - JOIN {enrol} e ON (e.id = ue.enrolid AND e.id = :enrolid))"; - - $order = ' ORDER BY u.lastname ASC, u.firstname ASC'; - - if (!$this->is_validating()) { - $potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params); - if ($potentialmemberscount > 100) { - return $this->too_many_results($search, $potentialmemberscount); - } - } - - $availableusers = $DB->get_records_sql($fields . $sql . $order, $params); - - if (empty($availableusers)) { - return array(); - } - - - if ($search) { - $groupname = get_string('enrolcandidatesmatching', 'enrol', $search); - } else { - $groupname = get_string('enrolcandidates', 'enrol'); - } - - return array($groupname => $availableusers); - } - - protected function get_options() { - $options = parent::get_options(); - $options['enrolid'] = $this->enrolid; - $options['file'] = 'enrol/apply/selectlib.php'; - return $options; - } -} - -/** - * Enroled users - */ -class enrol_apply_current_participant extends user_selector_base { - protected $courseid; - protected $enrolid; - - public function __construct($name, $options) { - $this->enrolid = $options['enrolid']; - parent::__construct($name, $options); - } - - /** - * Candidate users - * @param $search - * @return array - */ - public function find_users($search) { - global $DB; - //by default wherecondition retrieves all users except the deleted, not confirmed and guest - list($wherecondition, $params) = $this->search_sql($search, 'u'); - $params['enrolid'] = $this->enrolid; - - $fields = 'SELECT ' . $this->required_fields_sql('u'); - $countfields = 'SELECT COUNT(1)'; - - $sql = " FROM {user} u - JOIN {user_enrolments} ue ON (ue.userid = u.id AND ue.enrolid = :enrolid) - WHERE $wherecondition"; - - $order = ' ORDER BY u.lastname ASC, u.firstname ASC'; - - if (!$this->is_validating()) { - $potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params); - if ($potentialmemberscount > 100) { - return $this->too_many_results($search, $potentialmemberscount); - } - } - - $availableusers = $DB->get_records_sql($fields . $sql . $order, $params); - - if (empty($availableusers)) { - return array(); - } - - - if ($search) { - $groupname = get_string('enrolledusersmatching', 'enrol', $search); - } else { - $groupname = get_string('enrolledusers', 'enrol'); - } - - return array($groupname => $availableusers); - } - - protected function get_options() { - $options = parent::get_options(); - $options['enrolid'] = $this->enrolid; - $options['file'] = 'enrol/apply/apply_form.php'; - return $options; - } -} diff --git a/unenroluser.php b/unenroluser.php deleted file mode 100644 index f2b1912..0000000 --- a/unenroluser.php +++ /dev/null @@ -1,97 +0,0 @@ -dirroot/enrol/renderer.php"); - -$ueid = required_param('ue', PARAM_INT); // user enrolment id -$filter = optional_param('ifilter', 0, PARAM_INT); -$confirm = optional_param('confirm', false, PARAM_BOOL); - -// Get the user enrolment object -$ue = $DB->get_record('user_enrolments', array('id' => $ueid), '*', MUST_EXIST); -// Get the user for whom the enrolment is -$user = $DB->get_record('user', array('id'=>$ue->userid), '*', MUST_EXIST); -// Get the course the enrolment is to -//list($ctxsql, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx'); -$ctxsql = context_helper::get_preload_record_columns_sql('ctx'); -$sql = "SELECT c.*, $ctxsql - FROM {course} c - LEFT JOIN {enrol} e ON e.courseid = c.id - LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextcourse) - WHERE e.id = :enrolid"; -$params = array('enrolid' => $ue->enrolid, 'contextcourse' => CONTEXT_COURSE); -$course = $DB->get_record_sql($sql, $params, MUST_EXIST); -context_helper::preload_from_record($course); - - -// Make sure it's not the front page -if ($course->id == SITEID) { - redirect(new moodle_url('/')); -} - -// Obviously -require_login($course); -// Make sure the user can unenrol users. -require_capability("enrol/apply:unenrol", context_course::instance($course->id)); - -// Get the enrolment manager for this course -$manager = new course_enrolment_manager($PAGE, $course, $filter); -// Get an enrolment users table object. Doign this will automatically retrieve the the URL params -// relating to table the user was viewing before coming here, and allows us to return the user to the -// exact page of the users screen they can from. -$table = new course_enrolment_users_table($manager, $PAGE); - -// The URL of the enrolled users page for the course. -$usersurl = new moodle_url('/enrol/users.php', array('id' => $course->id)); -// The URl to return the user too after this screen. -$returnurl = new moodle_url($usersurl, $manager->get_url_params()+$table->get_url_params()); -// The URL of this page -$url = new moodle_url('/enrol/apply/unenroluser.php', $returnurl->params()); -$url->param('ue', $ueid); - -$PAGE->set_url($url); -$PAGE->set_pagelayout('admin'); -navigation_node::override_active_url($usersurl); - -list($instance, $plugin) = $manager->get_user_enrolment_components($ue); -if (!$plugin->allow_unenrol($instance) || $instance->enrol != 'apply' || !($plugin instanceof enrol_apply_plugin)) { - print_error('erroreditenrolment', 'enrol'); -} - -// If the unenrolment has been confirmed and the sesskey is valid unenrol the user. -if ($confirm && confirm_sesskey() && $manager->unenrol_user($ue)) { - redirect($returnurl); -} - -$yesurl = new moodle_url($PAGE->url, array('confirm'=>1, 'sesskey'=>sesskey())); -$message = get_string('unenroluser', 'enrol_self', array('user' => fullname($user, true), 'course' => format_string($course->fullname))); -$fullname = fullname($user); -$title = get_string('unenrol', 'enrol_self'); - -$PAGE->set_title($title); -$PAGE->set_heading($title); -$PAGE->navbar->add($title); -$PAGE->navbar->add($fullname); - -echo $OUTPUT->header(); -echo $OUTPUT->heading($fullname); -echo $OUTPUT->confirm($message, $yesurl, $returnurl); -echo $OUTPUT->footer(); From d4a946624fbecf0a1807d8760e3de7deec42c4a1 Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Thu, 26 May 2016 16:51:44 +0200 Subject: [PATCH 11/28] Rename enrol_self to enrol_apply --- edit.php | 2 +- edit_form.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/edit.php b/edit.php index e91733e..49b7048 100644 --- a/edit.php +++ b/edit.php @@ -43,7 +43,7 @@ if ($instanceid) { $instance->courseid = $course->id; } -$mform = new enrol_self_edit_form(NULL, array($instance, $plugin, $context)); +$mform = new enrol_apply_edit_form(NULL, array($instance, $plugin, $context)); if ($mform->is_cancelled()) { redirect($return); diff --git a/edit_form.php b/edit_form.php index ed97deb..bc0cc1c 100644 --- a/edit_form.php +++ b/edit_form.php @@ -14,7 +14,7 @@ defined('MOODLE_INTERNAL') || die(); require_once($CFG->libdir.'/formslib.php'); -class enrol_self_edit_form extends moodleform { +class enrol_apply_edit_form extends moodleform { function definition() { $mform = $this->_form; From 960bbbdc3d4af27af28b95fb765a865a8f20517e Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Thu, 26 May 2016 16:52:07 +0200 Subject: [PATCH 12/28] Remove unused code inherited from enrol_self plugin --- apply_form.php | 45 +-------------------------------------------- 1 file changed, 1 insertion(+), 44 deletions(-) diff --git a/apply_form.php b/apply_form.php index 77bc667..c1e405f 100644 --- a/apply_form.php +++ b/apply_form.php @@ -11,10 +11,9 @@ * ************************************************************************ */ /** - * Self enrol plugin implementation. + * Apply enrol plugin implementation. * * @package enrol - * @subpackage self * @copyright 2010 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -46,16 +45,6 @@ class enrol_apply_apply_form extends moodleform { $heading = $plugin->get_instance_name($instance); $mform->addElement('header', 'selfheader', $heading); - if ($instance->password) { - $heading = $plugin->get_instance_name($instance); - $mform->addElement('header', 'selfheader', $heading); - //change the id of self enrolment key input as there can be multiple self enrolment methods - $mform->addElement('passwordunmask', 'enrolpassword', get_string('password', 'enrol_self'), - array('id' => $instance->id."_enrolpassword")); - } else { - // nothing? - } - $mform->addElement('html', '

'.$instance->customtext1.'

'); $mform->addElement('textarea', 'applydescription', get_string('comment', 'enrol_apply'),'cols="80"'); @@ -107,38 +96,6 @@ class enrol_apply_apply_form extends moodleform { $errors = parent::validation($data, $files); $instance = $this->instance; - if ($instance->password) { - if ($data['enrolpassword'] !== $instance->password) { - if ($instance->customint1) { - $groups = $DB->get_records('groups', array('courseid'=>$instance->courseid), 'id ASC', 'id, enrolmentkey'); - $found = false; - foreach ($groups as $group) { - if (empty($group->enrolmentkey)) { - continue; - } - if ($group->enrolmentkey === $data['enrolpassword']) { - $found = true; - break; - } - } - if (!$found) { - // we can not hint because there are probably multiple passwords - $errors['enrolpassword'] = get_string('passwordinvalid', 'enrol_self'); - } - - } else { - $plugin = enrol_get_plugin('self'); - if ($plugin->get_config('showhint')) { - $textlib = textlib_get_instance(); - $hint = $textlib->substr($instance->password, 0, 1); - $errors['enrolpassword'] = get_string('passwordinvalidhint', 'enrol_self', $hint); - } else { - $errors['enrolpassword'] = get_string('passwordinvalid', 'enrol_self'); - } - } - } - } - return $errors; } } \ No newline at end of file From 990afdf8537f4031a67eb9fe1acc9a17a1940358 Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Thu, 26 May 2016 17:16:49 +0200 Subject: [PATCH 13/28] Remove unnecessary log action (already done in unenrolment method). Add file description --- unenrolself.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/unenrolself.php b/unenrolself.php index cf92998..77a875e 100644 --- a/unenrolself.php +++ b/unenrolself.php @@ -15,9 +15,12 @@ // along with Moodle. If not, see . /** - * Self enrolment plugin - support for user self unenrolment. + * User self unenrolment action and user secrity query for the enrol_apply plugin. + * The presence of this file plus the capability 'apply:unenrolself' + * results in a self unenrolment link in the course administration + * navigation ('Unenrol me from ...'). * - * @package enrol_self + * @package enrol_apply * @copyright 2010 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -49,11 +52,6 @@ $PAGE->set_title($plugin->get_instance_name($instance)); if ($confirm and confirm_sesskey()) { $plugin->unenrol_user($instance, $USER->id); - - // Deprecated fixed by Shiro - //add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //TODO: there should be userid somewhere! - $context = context_course::instance($course->id); - \core\event\user_enrolment_deleted::delete(array('context' => $context))->trigger(); redirect(new moodle_url('/index.php')); } From 0e5b8f8b8b6fb3998d9fad289bf616aa700637c2 Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Sun, 29 May 2016 14:11:35 +0200 Subject: [PATCH 14/28] Refactor capabilities Change name of enrol/apply:manage to enrol/apply:manageapplications to avoid confusion with reserved enrol/xxx:manage for manual enrolment status changes (see also allow_manage() method). Remove unnecessary enrol/apply:enrol capability (plugin does not allow manual enrolment of other users) Add description comments. --- db/access.php | 21 +++++++++------------ lang/ca/enrol_apply.php | 2 +- lang/de/enrol_apply.php | 2 +- lang/en/enrol_apply.php | 3 +-- lang/en_us/en_us_enrol_apply.php | 2 +- lang/es/enrol_apply.php | 2 +- lang/it/enrol_apply.php | 2 +- lang/pt_br/enrol_apply.php | 2 +- lang/zh_cn/enrol_apply.php | 2 +- lib.php | 2 +- manage.php | 4 ++-- 11 files changed, 20 insertions(+), 24 deletions(-) diff --git a/db/access.php b/db/access.php index fc120ab..d5609ef 100644 --- a/db/access.php +++ b/db/access.php @@ -24,18 +24,8 @@ defined('MOODLE_INTERNAL') || die(); $capabilities = array( + /* Add, edit or remove manual enrol instance. */ 'enrol/apply:config' => array( - - 'captype' => 'write', - 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( - 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW, - ) - ), - - 'enrol/apply:manage' => array( - 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, 'archetypes' => array( @@ -44,7 +34,12 @@ $capabilities = array( ) ), - 'enrol/apply:enrol' => array( + /** + * Enrolment approval. + * If granted on CONTEXT_SYSTEM level it allows approval for all courses + * at Site Administration -> Courses -> Manage enrolment applications. + */ + 'enrol/apply:manageapplications' => array( 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, 'archetypes' => array( @@ -53,6 +48,7 @@ $capabilities = array( ) ), + /* Unenrol a user */ 'enrol/apply:unenrol' => array( 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, @@ -62,6 +58,7 @@ $capabilities = array( ) ), + /* Allow a user to unenrol himself */ 'enrol/apply:unenrolself' => array( 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, diff --git a/lang/ca/enrol_apply.php b/lang/ca/enrol_apply.php index 7473bd5..5c2a903 100644 --- a/lang/ca/enrol_apply.php +++ b/lang/ca/enrol_apply.php @@ -35,7 +35,7 @@ $string['status'] = 'Permet inscripció prèvia aprovació'; $string['confirmenrol'] = 'Gestionar sol·licituds'; $string['apply:config'] = 'Configurar instàncies d\'Inscripció prèvia aprovació'; // Needs more insight -$string['apply:manage'] = 'Gestionar la Inscripció prèvia aprovació'; // Needs more insight +$string['apply:manageapplications'] = 'Gestionar la Inscripció prèvia aprovació'; // Needs more insight $string['apply:unenrol'] = 'Cancel·lar usuaris del curs'; // Needs more insight $string['notification'] = 'Sol·licitud d\'inscripció enviada correctament.

Rebràs una notificació per correu electrònic un cop estigui confirmada la inscripció.'; diff --git a/lang/de/enrol_apply.php b/lang/de/enrol_apply.php index 42fe5bf..91f042c 100644 --- a/lang/de/enrol_apply.php +++ b/lang/de/enrol_apply.php @@ -40,7 +40,7 @@ $string['status'] = 'Bestätigung der Kurseinschreibung erlauben'; $string['confirmenrol'] = 'Einschreibeanfragen bearbeiten'; $string['apply:config'] = 'Einschreibungsbelegstellen anlegen'; -$string['apply:manage'] = 'Einschreibungsanfragen verwalten'; +$string['apply:manageapplications'] = 'Einschreibungsanfragen verwalten'; $string['apply:unenrol'] = 'Benutzer aus dem Kurs entfernen'; $string['notification'] = 'Einschreibungsantrag wurde erfolgreich gesendet..

Sie werden via Mail informiert, sobald Ihre Einschreibung bestätigt wurde.'; diff --git a/lang/en/enrol_apply.php b/lang/en/enrol_apply.php index 2fb9ed9..cb7cbb1 100644 --- a/lang/en/enrol_apply.php +++ b/lang/en/enrol_apply.php @@ -56,8 +56,7 @@ $string['status'] = 'Allow Course enrol confirmation'; $string['confirmenrol'] = 'Manage application'; $string['apply:config'] = 'Configure apply enrol instances'; -$string['apply:enrol'] = 'Enrol users'; -$string['apply:manage'] = 'Manage apply enrolment'; +$string['apply:manageapplications'] = 'Manage apply enrolment'; $string['apply:unenrol'] = 'Cancel users from the course'; $string['apply:unenrolself'] = 'Cancel self from the course'; diff --git a/lang/en_us/en_us_enrol_apply.php b/lang/en_us/en_us_enrol_apply.php index b720c6c..08da6af 100644 --- a/lang/en_us/en_us_enrol_apply.php +++ b/lang/en_us/en_us_enrol_apply.php @@ -35,7 +35,7 @@ $string['status'] = 'Allow course enroll confirmation'; $string['confirmenroll'] = 'Manage application'; $string['apply:config'] = 'Configure apply enroll instances'; -$string['apply:manage'] = 'Manage apply enrollment'; +$string['apply:manageapplications'] = 'Manage apply enrollment'; $string['apply:unenroll'] = 'Cancel users from the course'; $string['apply:unenrollapply'] = 'Cancel self from the course'; diff --git a/lang/es/enrol_apply.php b/lang/es/enrol_apply.php index 69d19f4..e88807b 100644 --- a/lang/es/enrol_apply.php +++ b/lang/es/enrol_apply.php @@ -35,7 +35,7 @@ $string['status'] = 'Aceptar matriculación tras aprobación'; $string['confirmenrol'] = 'Gestionar solicitudes'; $string['apply:config'] = 'Configurar instancias de matrículas solicitadas'; // Needs more insight -$string['apply:manage'] = 'Gestionar matrículas solicitadas'; // Needs more insight +$string['apply:manageapplications'] = 'Gestionar matrículas solicitadas'; // Needs more insight $string['apply:unenrol'] = 'Cancelar usuarios del curso'; // Needs more insight $string['notification'] = 'Solicitud de matriculación enviada correctamente.

Será notificado por correo electrónico en cuanto se confirme su matriculación.'; diff --git a/lang/it/enrol_apply.php b/lang/it/enrol_apply.php index 744a71b..56ac011 100644 --- a/lang/it/enrol_apply.php +++ b/lang/it/enrol_apply.php @@ -35,7 +35,7 @@ $string['status'] = 'Permetti la conferma di iscrizione al corso'; $string['confirmenrol'] = 'Gestisci l\'applicazione'; $string['apply:config'] = 'Configura le istanze del plugin'; -$string['apply:manage'] = 'Gestisci le richieste di iscrizione'; +$string['apply:manageapplications'] = 'Gestisci le richieste di iscrizione'; $string['apply:unenrol'] = 'Cancella gli utenti dal corso'; $string['apply:unenrolself'] = 'Permetti all\'utente di disiscriversi dal corso'; diff --git a/lang/pt_br/enrol_apply.php b/lang/pt_br/enrol_apply.php index b448761..08fe0fb 100644 --- a/lang/pt_br/enrol_apply.php +++ b/lang/pt_br/enrol_apply.php @@ -35,7 +35,7 @@ $string['status'] = 'Aceitar matrícula após aprovação'; $string['confirmenrol'] = 'Gerenciar solicitações'; $string['apply:config'] = 'Configurar instâncias de matrículas solicitadas'; // Needs more insight -$string['apply:manage'] = 'Gerenciar matrículas solicitadas'; // Needs more insight +$string['apply:manageapplications'] = 'Gerenciar matrículas solicitadas'; // Needs more insight $string['apply:unenrol'] = 'Cancelar usuários do curso'; // Needs more insight $string['notification'] = 'Solicitação de matrícula enviada com sucesso.

Você será notificado por e-mail quando a sua matrícula for confirmada.'; diff --git a/lang/zh_cn/enrol_apply.php b/lang/zh_cn/enrol_apply.php index e5d837e..faccad8 100644 --- a/lang/zh_cn/enrol_apply.php +++ b/lang/zh_cn/enrol_apply.php @@ -35,7 +35,7 @@ $string['status'] = '允许选课确认'; $string['confirmenrol'] = '管理申请'; $string['apply:config'] = '配置选课确认的实例'; -$string['apply:manage'] = '管理选课申请'; +$string['apply:manageapplications'] = '管理选课申请'; $string['apply:unenrol'] = '从课程中取消用户的选课'; $string['apply:unenrolself'] = '从课程中取消自身的选课'; diff --git a/lib.php b/lib.php index 7a9196f..f70d236 100644 --- a/lib.php +++ b/lib.php @@ -113,7 +113,7 @@ class enrol_apply_plugin extends enrol_plugin { $icons[] = $OUTPUT->action_icon($editlink, new pix_icon('t/edit', get_string('edit'), 'core', array('class' => 'iconsmall'))); } - if (has_capability('enrol/apply:manage', $context)) { + if (has_capability('enrol/apply:manageapplications', $context)) { $managelink = new moodle_url("/enrol/apply/manage.php", array('id'=>$instance->id)); $icons[] = $OUTPUT->action_icon($managelink, new pix_icon('i/users', get_string('confirmenrol', 'enrol_apply'), 'core', array('class'=>'iconsmall'))); } diff --git a/manage.php b/manage.php index eab4cb7..97ccc9e 100644 --- a/manage.php +++ b/manage.php @@ -23,14 +23,14 @@ require_login(); $manageurlparams = array(); if ($id == null) { $context = context_system::instance(); - require_capability('enrol/apply:manage', $context); + require_capability('enrol/apply:manageapplications', $context); $pageheading = get_string('confirmusers', 'enrol_apply'); } else { $instance = $DB->get_record('enrol', array('id'=>$id, 'enrol'=>'apply'), '*', MUST_EXIST); require_course_login($instance->courseid); $course = get_course($instance->courseid); $context = context_course::instance($course->id, MUST_EXIST); - require_capability('moodle/course:enrolreview', $context); + require_capability('enrol/apply:manageapplications', $context); $manageurlparams['id'] = $instance->id; $pageheading = $course->fullname; } From e082e5256722c3ac4158f4fdd637885085cc2ad3 Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Tue, 31 May 2016 12:07:01 +0200 Subject: [PATCH 15/28] Fix: Even confirmed applications were showed on admin mange page. --- manage_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manage_table.php b/manage_table.php index f0601a5..68044b0 100644 --- a/manage_table.php +++ b/manage_table.php @@ -41,7 +41,7 @@ class enrol_apply_manage_table extends table_sql { $sqlwhere .= " AND e.id = :enrolid"; $sqlparams['enrolid'] = $enrolid; } else { - $sqlwhere = "e.enrol = :enrol"; + $sqlwhere .= " AND e.enrol = :enrol"; $sqlparams['enrol'] = 'apply'; } From 7bc73894ad3e96cd7b3809d4297429f448e9339a Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Tue, 31 May 2016 12:56:24 +0200 Subject: [PATCH 16/28] Optimize manage action handling --- manage.php | 20 ++++++-------------- renderer.php | 25 +++++-------------------- 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/manage.php b/manage.php index 97ccc9e..9c09660 100644 --- a/manage.php +++ b/manage.php @@ -46,20 +46,12 @@ $PAGE->set_title(get_string('confirmusers', 'enrol_apply')); $PAGE->requires->css('/enrol/apply/style.css'); if ($userenrolments != null) { - $action = required_param('type', PARAM_TEXT); - switch ($action) { - case 'confirm': - confirmEnrolment($userenrolments); - break; - case 'wait': - waitEnrolment ($userenrolments); - break; - case 'cancel': - cancelEnrolment($userenrolments); - break; - default: - # code... - break; + if (optional_param('confirm', false, PARAM_BOOL)) { + confirmEnrolment($userenrolments); + } else if (optional_param('wait', false, PARAM_BOOL)) { + waitEnrolment ($userenrolments); + } else if (optional_param('cancel', false, PARAM_BOOL)) { + cancelEnrolment($userenrolments); } redirect($manageurl); } diff --git a/renderer.php b/renderer.php index da1124d..53e491e 100644 --- a/renderer.php +++ b/renderer.php @@ -36,32 +36,17 @@ class enrol_apply_renderer extends plugin_renderer_base { public function manage_form($table, $manageurl) { echo html_writer::start_tag('form', array('id' => 'enrol_apply_manage_form', 'method' => 'post', 'action' => $manageurl->out())); - echo html_writer::empty_tag('input', array('type' => 'hidden', 'id' => 'type', 'name' => 'type', 'value' => 'confirm')); $this->manage_table($table); echo html_writer::start_tag('p', array('align' => 'center')); - echo html_writer::empty_tag('input', array( - 'type' => 'button', - 'onclick' => 'doSubmit("confirm");', - 'value' => get_string('btnconfirm', 'enrol_apply'))); - echo html_writer::empty_tag('input', array( - 'type' => 'button', - 'onclick' => 'doSubmit("wait");', - 'value' => get_string('btnwait', 'enrol_apply'))); - echo html_writer::empty_tag('input', array( - 'type' => 'button', - 'onclick' => 'doSubmit("cancel");', - 'value' => get_string('btncancel', 'enrol_apply'))); + + echo html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'confirm', 'value' => get_string('btnconfirm', 'enrol_apply'))); + echo html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'wait', 'value' => get_string('btnwait', 'enrol_apply'))); + echo html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'cancel', 'value' => get_string('btncancel', 'enrol_apply'))); + echo html_writer::end_tag('p'); echo html_writer::end_tag('form'); - - $js = " - function doSubmit(type){ - document.getElementById('type').value=type; - document.getElementById('enrol_apply_manage_form').submit(); - }"; - echo html_writer::tag('script', $js, array('type' => 'text/javascript')); } public function manage_table($table) { From 762ed28d56b0add28810417a85ffded9300dbd5f Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Wed, 1 Jun 2016 12:34:36 +0200 Subject: [PATCH 17/28] Optimize confirm, wait and cancel enrolments functions. --- lib.php | 103 +++++++++++++++++++++++++++++++++++----------------- manage.php | 7 ++-- version.php | 2 +- 3 files changed, 74 insertions(+), 38 deletions(-) diff --git a/lib.php b/lib.php index f70d236..854875c 100644 --- a/lib.php +++ b/lib.php @@ -9,8 +9,11 @@ * ************************************************************************* * ************************************************************************ */ -class enrol_apply_plugin extends enrol_plugin { +/** User participation in course is suspended (used in user_enrolments->status) */ +define('ENROL_APPLY_USER_WAIT', 2); + +class enrol_apply_plugin extends enrol_plugin { /** * Add new instance of enrol plugin with default settings. * @param object $course @@ -196,50 +199,82 @@ class enrol_apply_plugin extends enrol_plugin { return $fields; } -} -function confirmEnrolment($enrols){ - global $DB; - global $CFG; - foreach ($enrols as $enrol){ - @$enroluser->id = $enrol; - @$enroluser->status = 0; - - if($DB->update_record('user_enrolments',$enroluser)){ - $userenrolments = $DB->get_record_sql('select * from '.$CFG->prefix.'user_enrolments where id='.$enrol); - $role = $DB->get_record_sql("select * from ".$CFG->prefix."role where archetype='student' limit 1"); - @$roleAssignments->userid = $userenrolments->userid; - @$roleAssignments->roleid = $role->id; - @$roleAssignments->contextid = 3; - @$roleAssignments->timemodified = time(); - @$roleAssignments->modifierid = 2; - $DB->insert_record('role_assignments',$roleAssignments); + function confirmEnrolment($enrols){ + global $DB; + foreach ($enrols as $enrol){ + // $userenrolment = $DB->get_record('user_enrolments', array('id' => $enrol), '*', MUST_EXIST); + $userenrolment = $DB->get_record_select( + 'user_enrolments', + 'id = :id AND (status = :enrolusersuspended OR status = :enrolapplyuserwait)', + array( + 'id' => $enrol, + 'enrolusersuspended' => ENROL_USER_SUSPENDED, + 'enrolapplyuserwait' => ENROL_APPLY_USER_WAIT), + '*', + MUST_EXIST); + + $instance = $DB->get_record('enrol', array('id' => $userenrolment->enrolid, 'enrol' => 'apply'), '*', MUST_EXIST); + + // Check privileges. + $context = context_course::instance($instance->courseid, MUST_EXIST); + if (!has_capability('enrol/apply:manageapplications', $context)) { + continue; + } + + $this->update_user_enrol($instance, $userenrolment->userid, ENROL_USER_ACTIVE); + $info = getRelatedInfo($enrol); $DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol)); sendConfirmMail($info); } } -} -function waitEnrolment($enrols){ - global $DB; - global $CFG; - foreach ($enrols as $enrol){ - @$enroluser->id = $enrol; - @$enroluser->status = 2; + function waitEnrolment($enrols){ + global $DB; + foreach ($enrols as $enrol){ + $userenrolment = $DB->get_record('user_enrolments', array('id' => $enrol, 'status' => ENROL_USER_SUSPENDED), '*', IGNORE_MISSING); - if($DB->update_record('user_enrolments',$enroluser)){ - $info = getRelatedInfo($enrol); - sendWaitMail($info); + if ($userenrolment != null) { + $instance = $DB->get_record('enrol', array('id' => $userenrolment->enrolid, 'enrol' => 'apply'), '*', MUST_EXIST); + + // Check privileges. + $context = context_course::instance($instance->courseid, MUST_EXIST); + if (!has_capability('enrol/apply:manageapplications', $context)) { + continue; + } + + $this->update_user_enrol($instance, $userenrolment->userid, ENROL_APPLY_USER_WAIT); + + $info = getRelatedInfo($enrol); + sendWaitMail($info); + } } } -} -function cancelEnrolment($enrols){ - global $DB; - foreach ($enrols as $enrol){ - $info = getRelatedInfo($enrol); - if($DB->delete_records('user_enrolments',array('id'=>$enrol))){ + function cancelEnrolment($enrols){ + global $DB; + foreach ($enrols as $enrol){ + $userenrolment = $DB->get_record_select( + 'user_enrolments', + 'id = :id AND (status = :enrolusersuspended OR status = :enrolapplyuserwait)', + array( + 'id' => $enrol, + 'enrolusersuspended' => ENROL_USER_SUSPENDED, + 'enrolapplyuserwait' => ENROL_APPLY_USER_WAIT), + '*', + MUST_EXIST); + + $instance = $DB->get_record('enrol', array('id' => $userenrolment->enrolid, 'enrol' => 'apply'), '*', MUST_EXIST); + + // Check privileges. + $context = context_course::instance($instance->courseid, MUST_EXIST); + if (!has_capability('enrol/apply:manageapplications', $context)) { + continue; + } + + $info = getRelatedInfo($enrol); + $this->unenrol_user($instance, $userenrolment->userid); $DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol)); sendCancelMail($info); } diff --git a/manage.php b/manage.php index 9c09660..e7f3413 100644 --- a/manage.php +++ b/manage.php @@ -46,12 +46,13 @@ $PAGE->set_title(get_string('confirmusers', 'enrol_apply')); $PAGE->requires->css('/enrol/apply/style.css'); if ($userenrolments != null) { + $enrolapply = enrol_get_plugin('apply'); if (optional_param('confirm', false, PARAM_BOOL)) { - confirmEnrolment($userenrolments); + $enrolapply->confirmEnrolment($userenrolments); } else if (optional_param('wait', false, PARAM_BOOL)) { - waitEnrolment ($userenrolments); + $enrolapply->waitEnrolment($userenrolments); } else if (optional_param('cancel', false, PARAM_BOOL)) { - cancelEnrolment($userenrolments); + $enrolapply->cancelEnrolment($userenrolments); } redirect($manageurl); } diff --git a/version.php b/version.php index 46fca18..4781493 100644 --- a/version.php +++ b/version.php @@ -19,7 +19,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2016042202; +$plugin->version = 2016042203; $plugin->requires = 2011080100; $plugin->maturity = MATURITY_STABLE; $plugin->release = 'Enrolment upon approval plugin Version 3.0-d'; From 51cf0cbf558d62623ade2a8310bd5719d31fd1d7 Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Wed, 1 Jun 2016 14:24:21 +0200 Subject: [PATCH 18/28] Optimize notification mail sending --- lib.php | 125 +++++++++++++++++---------------------------------- renderer.php | 43 ++++++++++++++++++ 2 files changed, 85 insertions(+), 83 deletions(-) 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 From b9f4434f06dd7a19dbbec05eaed3e01be8c5bd57 Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Wed, 1 Jun 2016 14:26:51 +0200 Subject: [PATCH 19/28] Move all functions inside class --- lib.php | 226 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 113 insertions(+), 113 deletions(-) diff --git a/lib.php b/lib.php index d82bb91..2a49582 100644 --- a/lib.php +++ b/lib.php @@ -77,8 +77,8 @@ class enrol_apply_plugin extends enrol_plugin { $applicationinfo->userenrolmentid = $userenrolment->id; $applicationinfo->comment = $applydescription; $DB->insert_record('enrol_apply_applicationinfo', $applicationinfo, false); - sendConfirmMailToTeachers($instance, $data, $applydescription); - sendConfirmMailToManagers($instance, $data, $applydescription); + $this->sendConfirmMailToTeachers($instance, $data, $applydescription); + $this->sendConfirmMailToManagers($instance, $data, $applydescription); // Deprecated fixed by Shiro //add_to_log($instance->courseid, 'course', 'enrol', '../enrol/users.php?id='.$instance->courseid, $instance->courseid); //there should be userid somewhere! @@ -224,9 +224,9 @@ class enrol_apply_plugin extends enrol_plugin { $this->update_user_enrol($instance, $userenrolment->userid, ENROL_USER_ACTIVE); - $info = getRelatedInfo($enrol); + $info = $this->getRelatedInfo($enrol); $DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol)); - sendConfirmMail($info); + $this->sendConfirmMail($info); } } @@ -246,8 +246,8 @@ class enrol_apply_plugin extends enrol_plugin { $this->update_user_enrol($instance, $userenrolment->userid, ENROL_APPLY_USER_WAIT); - $info = getRelatedInfo($enrol); - sendWaitMail($info); + $info = $this->getRelatedInfo($enrol); + $this->sendWaitMail($info); } } } @@ -273,147 +273,147 @@ class enrol_apply_plugin extends enrol_plugin { continue; } - $info = getRelatedInfo($enrol); + $info = $this->getRelatedInfo($enrol); $this->unenrol_user($instance, $userenrolment->userid); $DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol)); - sendCancelMail($info); + $this->sendCancelMail($info); } } -} -function sendCancelMail($info){ - global $DB; - global $CFG; + function sendCancelMail($info){ + global $DB; + global $CFG; - $replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); - $body = get_config('enrol_apply', 'cancelmailcontent'); - $body = updateMailContent($body,$replace); - $contact = core_user::get_support_user(); - email_to_user($info, $contact, get_config('enrol_apply', 'cancelmailsubject'), html_to_text($body), $body); -} + $replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); + $body = get_config('enrol_apply', 'cancelmailcontent'); + $body = $this->updateMailContent($body,$replace); + $contact = core_user::get_support_user(); + email_to_user($info, $contact, get_config('enrol_apply', 'cancelmailsubject'), html_to_text($body), $body); + } -function sendConfirmMail($info){ - global $DB; - global $CFG; + function sendConfirmMail($info){ + global $DB; + global $CFG; - $replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); - $body = get_config('enrol_apply', 'confirmmailcontent'); - $body = updateMailContent($body,$replace); - $contact = core_user::get_support_user(); - email_to_user($info, $contact, get_config('enrol_apply', 'confirmmailsubject'), html_to_text($body), $body); -} + $replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); + $body = get_config('enrol_apply', 'confirmmailcontent'); + $body = $this->updateMailContent($body,$replace); + $contact = core_user::get_support_user(); + email_to_user($info, $contact, get_config('enrol_apply', 'confirmmailsubject'), html_to_text($body), $body); + } -function sendWaitMail($info){ - global $DB; - global $CFG; - //global $USER; - - $replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); - $body = get_config('enrol_apply', 'waitmailcontent'); - $body = updateMailContent($body,$replace); - $contact = get_admin(); - //confirm mail will sent by the admin - //$contact = $USER; - email_to_user($info, $contact, get_config('enrol_apply', 'waitmailsubject'), html_to_text($body), $body); -} + function sendWaitMail($info){ + global $DB; + global $CFG; + //global $USER; + + $replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); + $body = get_config('enrol_apply', 'waitmailcontent'); + $body = $this->updateMailContent($body,$replace); + $contact = get_admin(); + //confirm mail will sent by the admin + //$contact = $USER; + email_to_user($info, $contact, get_config('enrol_apply', 'waitmailsubject'), html_to_text($body), $body); + } -function sendConfirmMailToTeachers($instance,$info,$applydescription){ - global $DB; - global $CFG; - global $USER; + function sendConfirmMailToTeachers($instance,$info,$applydescription){ + global $DB; + global $CFG; + global $USER; - $courseid = $instance->courseid; - $instanceid = $instance->id; + $courseid = $instance->courseid; + $instanceid = $instance->id; - if($instance->customint3 == 1){ - $course = get_course($courseid); - $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->customint3 == 1){ + $course = get_course($courseid); + $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; - } + 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; - } + $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)); + $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); + 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(); + $contact = core_user::get_support_user(); - foreach($teachers as $teacher){ - $editTeacher = $DB->get_record('user',array('id'=>$teacher->userid)); + foreach($teachers as $teacher){ + $editTeacher = $DB->get_record('user',array('id'=>$teacher->userid)); - $info = $editTeacher; - $info->coursename = $course->fullname; - email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body); + $info = $editTeacher; + $info->coursename = $course->fullname; + email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body); + } } } -} -function sendConfirmMailToManagers($instance,$info,$applydescription){ - global $DB; - global $CFG; - global $USER; + function sendConfirmMailToManagers($instance,$info,$applydescription){ + global $DB; + global $CFG; + global $USER; - $courseid = $instance->courseid; + $courseid = $instance->courseid; - if(get_config('enrol_apply', 'sendmailtomanager') == 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)); + if(get_config('enrol_apply', 'sendmailtomanager') == 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)); - if (!$instance->customint1) { - $info = null; - } + 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; - } + $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'); + $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); + 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(); + $contact = core_user::get_support_user(); - foreach($managers as $manager){ - $userWithManagerRole = $DB->get_record('user',array('id'=>$manager->userid)); + foreach($managers as $manager){ + $userWithManagerRole = $DB->get_record('user',array('id'=>$manager->userid)); - $info = $userWithManagerRole; - $info->coursename = $course->fullname; - email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body); + $info = $userWithManagerRole; + $info->coursename = $course->fullname; + email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body); + } } } -} -function getRelatedInfo($enrolid){ - global $DB; - global $CFG; - return $DB->get_record_sql('select u.*,c.fullname as coursename 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.id='.$enrolid); -} + function getRelatedInfo($enrolid){ + global $DB; + global $CFG; + return $DB->get_record_sql('select u.*,c.fullname as coursename 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.id='.$enrolid); + } -function updateMailContent($content,$replace){ - foreach ($replace as $key=>$val) { - $content = str_replace("{".$key."}",$val,$content); + function updateMailContent($content,$replace){ + foreach ($replace as $key=>$val) { + $content = str_replace("{".$key."}",$val,$content); + } + return $content; } - return $content; } From d44a738a17f212e96634fec84f9794a3b6cef50a Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Wed, 1 Jun 2016 14:37:28 +0200 Subject: [PATCH 20/28] Remove event triggering, it is already done by the enrol_user method --- lib.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/lib.php b/lib.php index 2a49582..40c7422 100644 --- a/lib.php +++ b/lib.php @@ -79,18 +79,6 @@ class enrol_apply_plugin extends enrol_plugin { $DB->insert_record('enrol_apply_applicationinfo', $applicationinfo, false); $this->sendConfirmMailToTeachers($instance, $data, $applydescription); $this->sendConfirmMailToManagers($instance, $data, $applydescription); - - // Deprecated fixed by Shiro - //add_to_log($instance->courseid, 'course', 'enrol', '../enrol/users.php?id='.$instance->courseid, $instance->courseid); //there should be userid somewhere! - $context = context_course::instance($instance->courseid); - \core\event\user_enrolment_created::create( - array( - 'objectid' => $instance->id, - 'courseid' => $instance->courseid, - 'context' => $context, - 'relateduserid' => $USER->id, - 'other' => array('enrol' => 'apply') - ))->trigger(); redirect("$CFG->wwwroot/course/view.php?id=$instance->courseid"); } From 165ffcfe34bd4c4a3d7c79e5cba8c78db47537d2 Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Wed, 1 Jun 2016 15:49:22 +0200 Subject: [PATCH 21/28] Fix: Wrong param type (PARAM_TEXT changed to PARAM_RAW for admin_setting_confightmleditor fields) --- settings.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/settings.php b/settings.php index 33a0836..61d9053 100644 --- a/settings.php +++ b/settings.php @@ -32,7 +32,7 @@ if ($ADMIN->fulltree) { get_string('confirmmailcontent', 'enrol_apply'), get_string('confirmmailcontent_desc', 'enrol_apply'), null, - PARAM_TEXT)); + PARAM_RAW)); // Wait mail settings. $settings->add(new admin_setting_heading( @@ -51,7 +51,7 @@ if ($ADMIN->fulltree) { get_string('waitmailcontent', 'enrol_apply'), get_string('waitmailcontent_desc', 'enrol_apply'), null, - PARAM_TEXT)); + PARAM_RAW)); // Cancel mail settings $settings->add(new admin_setting_heading( @@ -70,7 +70,7 @@ if ($ADMIN->fulltree) { get_string('cancelmailcontent', 'enrol_apply'), get_string('cancelmailcontent_desc', 'enrol_apply'), null, - PARAM_TEXT)); + PARAM_RAW)); // Notification settings. $settings->add(new admin_setting_heading( From 7c38a66258298ea1fc7b497935354f60de6fea5a Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Wed, 1 Jun 2016 15:52:59 +0200 Subject: [PATCH 22/28] Optimize user notifications for confirm, wait, cancel actions. --- lib.php | 66 +++++++++++++++++++-------------------------------------- 1 file changed, 22 insertions(+), 44 deletions(-) diff --git a/lib.php b/lib.php index 40c7422..ec816b6 100644 --- a/lib.php +++ b/lib.php @@ -211,10 +211,11 @@ class enrol_apply_plugin extends enrol_plugin { } $this->update_user_enrol($instance, $userenrolment->userid, ENROL_USER_ACTIVE); - - $info = $this->getRelatedInfo($enrol); $DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol)); - $this->sendConfirmMail($info); + + $subject = get_config('enrol_apply', 'confirmmailsubject'); + $body = get_config('enrol_apply', 'confirmmailcontent'); + $this->send_mail_to_applicant($instance, $userenrolment->userid, $subject, $body); } } @@ -234,8 +235,9 @@ class enrol_apply_plugin extends enrol_plugin { $this->update_user_enrol($instance, $userenrolment->userid, ENROL_APPLY_USER_WAIT); - $info = $this->getRelatedInfo($enrol); - $this->sendWaitMail($info); + $subject = get_config('enrol_apply', 'waitmailsubject'); + $body = get_config('enrol_apply', 'waitmailcontent'); + $this->send_mail_to_applicant($instance, $userenrolment->userid, $subject, $body); } } } @@ -261,47 +263,25 @@ class enrol_apply_plugin extends enrol_plugin { continue; } - $info = $this->getRelatedInfo($enrol); $this->unenrol_user($instance, $userenrolment->userid); $DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol)); - $this->sendCancelMail($info); + + $subject = get_config('enrol_apply', 'cancelmailsubject'); + $body = get_config('enrol_apply', 'cancelmailcontent'); + $this->send_mail_to_applicant($instance, $userenrolment->userid, $subject, $body); } } - function sendCancelMail($info){ + function send_mail_to_applicant($instance, $userid, $subject, $body) { global $DB; global $CFG; - $replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); - $body = get_config('enrol_apply', 'cancelmailcontent'); - $body = $this->updateMailContent($body,$replace); - $contact = core_user::get_support_user(); - email_to_user($info, $contact, get_config('enrol_apply', 'cancelmailsubject'), html_to_text($body), $body); - } - - function sendConfirmMail($info){ - global $DB; - global $CFG; + $course = get_course($instance->courseid); + $user = core_user::get_user($userid); - $replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); - $body = get_config('enrol_apply', 'confirmmailcontent'); - $body = $this->updateMailContent($body,$replace); + $body = $this->updateMailContent($body, $course, $user); $contact = core_user::get_support_user(); - email_to_user($info, $contact, get_config('enrol_apply', 'confirmmailsubject'), html_to_text($body), $body); - } - - function sendWaitMail($info){ - global $DB; - global $CFG; - //global $USER; - - $replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); - $body = get_config('enrol_apply', 'waitmailcontent'); - $body = $this->updateMailContent($body,$replace); - $contact = get_admin(); - //confirm mail will sent by the admin - //$contact = $USER; - email_to_user($info, $contact, get_config('enrol_apply', 'waitmailsubject'), html_to_text($body), $body); + email_to_user($user, $contact, $subject, html_to_text($body), $body); } function sendConfirmMailToTeachers($instance,$info,$applydescription){ @@ -391,14 +371,12 @@ class enrol_apply_plugin extends enrol_plugin { } } - function getRelatedInfo($enrolid){ - global $DB; - global $CFG; - return $DB->get_record_sql('select u.*,c.fullname as coursename 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.id='.$enrolid); - } - - function updateMailContent($content,$replace){ + function updateMailContent($content, $course, $user) { + $replace = array( + 'firstname' => $user->firstname, + 'content' => format_string($course->fullname), + 'lastname' => $user->lastname, + 'username' => $user->username); foreach ($replace as $key=>$val) { $content = str_replace("{".$key."}",$val,$content); } From cec7f27c2938701335fce60ea499cea927bb0b5e Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Wed, 1 Jun 2016 17:02:57 +0200 Subject: [PATCH 23/28] Optimize sending application notification to teachers and managers. --- lib.php | 122 ++++++++++++++++++--------------------------------- renderer.php | 56 +++++++++++------------ 2 files changed, 70 insertions(+), 108 deletions(-) diff --git a/lib.php b/lib.php index ec816b6..b8f377d 100644 --- a/lib.php +++ b/lib.php @@ -62,11 +62,6 @@ class enrol_apply_plugin extends enrol_plugin { if ($data = $form->get_data()) { // Only process when form submission is for this instance (multi instance support). if ($data->instance == $instance->id) { - $userInfo = $data; - $applydescription = $userInfo->applydescription; - unset($userInfo->applydescription); - $userInfo->id = $USER->id; - $timestart = 0; $timeend = 0; $roleid = $instance->roleid; @@ -75,10 +70,10 @@ class enrol_apply_plugin extends enrol_plugin { $userenrolment = $DB->get_record('user_enrolments', array('userid' => $USER->id, 'enrolid' => $instance->id), 'id', MUST_EXIST); $applicationinfo = new stdClass(); $applicationinfo->userenrolmentid = $userenrolment->id; - $applicationinfo->comment = $applydescription; + $applicationinfo->comment = $data->applydescription; $DB->insert_record('enrol_apply_applicationinfo', $applicationinfo, false); - $this->sendConfirmMailToTeachers($instance, $data, $applydescription); - $this->sendConfirmMailToManagers($instance, $data, $applydescription); + + $this->send_application_notification($instance, $USER->id, $data); redirect("$CFG->wwwroot/course/view.php?id=$instance->courseid"); } @@ -284,89 +279,56 @@ class enrol_apply_plugin extends enrol_plugin { email_to_user($user, $contact, $subject, html_to_text($body), $body); } - function sendConfirmMailToTeachers($instance,$info,$applydescription){ - global $DB; - global $CFG; - global $USER; - - $courseid = $instance->courseid; - $instanceid = $instance->id; - - if($instance->customint3 == 1){ - $course = get_course($courseid); - $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)); + function send_application_notification($instance, $userid, $data) { + global $PAGE; - if (!$instance->customint1) { - $info = null; - } + $renderer = $PAGE->get_renderer('enrol_apply'); - $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); + $course = get_course($instance->courseid); + $user = core_user::get_user($userid); + $contact = core_user::get_support_user(); - $contact = core_user::get_support_user(); + // Include standard user profile fields? + $standarduserfields = null; + if ($instance->customint1) { + $standarduserfields = $data; + unset($standarduserfields->applydescription); + } - foreach($teachers as $teacher){ - $editTeacher = $DB->get_record('user',array('id'=>$teacher->userid)); + // Include extra user profile fields? + $extrauserfields = 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); + $extrauserfields = $user->profile; + } - $info = $editTeacher; - $info->coursename = $course->fullname; - email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body); + // Send notification to Teachers? Instance depending. + if ($instance->customint3 == 1) { + $context = context_course::instance($instance->courseid); + $editingteacherroles = get_archetype_roles('editingteacher'); + $editingteacherrole = reset($editingteacherroles); + $teachers = get_role_users($editingteacherrole->id, $context); + + $manageurl = new moodle_url("/enrol/apply/manage.php", array('id' => $instance->id)); + $body = $renderer->application_notification_mail_body($course, $user, $manageurl, $data->applydescription, $standarduserfields, $extrauserfields); + foreach ($teachers as $teacher) { + email_to_user($teacher, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body); } } - } - function sendConfirmMailToManagers($instance,$info,$applydescription){ - global $DB; - global $CFG; - global $USER; - - $courseid = $instance->courseid; - - if(get_config('enrol_apply', 'sendmailtomanager') == 1){ - $course = get_course($courseid); + // Send notification to managers in system context? + if (get_config('enrol_apply', 'sendmailtomanager') == 1) { $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; - } + $managerroles = get_archetype_roles('manager'); + $managerrole = reset($editingteacherroles); + $managers = get_role_users($managerrole->id, $context); $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)); - - $info = $userWithManagerRole; - $info->coursename = $course->fullname; - email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body); + $body = $renderer->application_notification_mail_body($course, $user, $manageurl, $data->applydescription, $standarduserfields, $extrauserfields); + foreach ($managers as $manager) { + email_to_user($manager, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body); } } } diff --git a/renderer.php b/renderer.php index 902902c..74c2e0a 100644 --- a/renderer.php +++ b/renderer.php @@ -72,40 +72,40 @@ 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) { + public function application_notification_mail_body($course, $user, $manageurl, $applydescription, $standarduserfields = null, $extrauserfields = 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){ + if($standarduserfields){ $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.'

'; + $body .= '

'. get_string('firstname') .': '.$standarduserfields->firstname.'

'; + $body .= '

'. get_string('lastname') .': '.$standarduserfields->lastname.'

'; + $body .= '

'. get_string('email') .': '.$standarduserfields->email.'

'; + $body .= '

'. get_string('city') .': '.$standarduserfields->city.'

'; + $body .= '

'. get_string('country') .': '.$standarduserfields->country.'

'; + $body .= '

'. get_string('preferredlanguage') .': '.$standarduserfields->lang.'

'; + $body .= '

'. get_string('description') .': '.$standarduserfields->description_editor['text'].'

'; + + $body .= '

'. get_string('firstnamephonetic') .': '.$standarduserfields->firstnamephonetic.'

'; + $body .= '

'. get_string('lastnamephonetic') .': '.$standarduserfields->lastnamephonetic.'

'; + $body .= '

'. get_string('middlename') .': '.$standarduserfields->middlename.'

'; + $body .= '

'. get_string('alternatename') .': '.$standarduserfields->alternatename.'

'; + $body .= '

'. get_string('url') .': '.$standarduserfields->url.'

'; + $body .= '

'. get_string('icqnumber') .': '.$standarduserfields->icq.'

'; + $body .= '

'. get_string('skypeid') .': '.$standarduserfields->skype.'

'; + $body .= '

'. get_string('aimid') .': '.$standarduserfields->aim.'

'; + $body .= '

'. get_string('yahooid') .': '.$standarduserfields->yahoo.'

'; + $body .= '

'. get_string('msnid') .': '.$standarduserfields->msn.'

'; + $body .= '

'. get_string('idnumber') .': '.$standarduserfields->idnumber.'

'; + $body .= '

'. get_string('institution') .': '.$standarduserfields->institution.'

'; + $body .= '

'. get_string('department') .': '.$standarduserfields->department.'

'; + $body .= '

'. get_string('phone') .': '.$standarduserfields->phone1.'

'; + $body .= '

'. get_string('phone2') .': '.$standarduserfields->phone2.'

'; + $body .= '

'. get_string('address') .': '.$standarduserfields->address.'

'; } - if($extra){ - foreach ($extra as $key => $value) { + if($extrauserfields){ + foreach ($extrauserfields as $key => $value) { $body .= '

'. $key .': '.$value.'

'; } } From 256c3e1b67940f112128fdbea376b180617eb451 Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Wed, 1 Jun 2016 17:12:52 +0200 Subject: [PATCH 24/28] Use renderer for edit page. --- edit.php | 6 ++---- renderer.php | 7 +++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/edit.php b/edit.php index 49b7048..ae033a3 100644 --- a/edit.php +++ b/edit.php @@ -78,7 +78,5 @@ if ($mform->is_cancelled()) { $PAGE->set_heading(format_string($course->fullname)); $PAGE->set_title(get_string('pluginname', 'enrol_apply')); -echo $OUTPUT->header(); -echo $OUTPUT->heading(get_string('pluginname', 'enrol_apply')); -$mform->display(); -echo $OUTPUT->footer(); +$renderer = $PAGE->get_renderer('enrol_apply'); +$renderer->edit_page($mform); diff --git a/renderer.php b/renderer.php index 74c2e0a..b9681a8 100644 --- a/renderer.php +++ b/renderer.php @@ -34,6 +34,13 @@ class enrol_apply_renderer extends plugin_renderer_base { echo $this->footer(); } + public function edit_page($mform) { + echo $this->header(); + echo $this->heading(get_string('pluginname', 'enrol_apply')); + $mform->display(); + echo $this->footer(); + } + public function manage_form($table, $manageurl) { echo html_writer::start_tag('form', array('id' => 'enrol_apply_manage_form', 'method' => 'post', 'action' => $manageurl->out())); From 4235cb06b096f843e361cdffc265351e18ab3649 Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Wed, 1 Jun 2016 20:01:23 +0200 Subject: [PATCH 25/28] Fixes --- lib.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib.php b/lib.php index b8f377d..cb84b2d 100644 --- a/lib.php +++ b/lib.php @@ -280,7 +280,7 @@ class enrol_apply_plugin extends enrol_plugin { } function send_application_notification($instance, $userid, $data) { - global $PAGE; + global $CFG, $PAGE; $renderer = $PAGE->get_renderer('enrol_apply'); @@ -291,7 +291,7 @@ class enrol_apply_plugin extends enrol_plugin { // Include standard user profile fields? $standarduserfields = null; if ($instance->customint1) { - $standarduserfields = $data; + $standarduserfields = clone $data; unset($standarduserfields->applydescription); } @@ -299,7 +299,6 @@ class enrol_apply_plugin extends enrol_plugin { $extrauserfields = 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); $extrauserfields = $user->profile; } From 0211dbfd10fb416c653c064126f8b0f7bdfc8a92 Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Wed, 1 Jun 2016 20:01:32 +0200 Subject: [PATCH 26/28] Optimize apply_form --- apply_form.php | 45 +++++++++++---------------------------------- 1 file changed, 11 insertions(+), 34 deletions(-) diff --git a/apply_form.php b/apply_form.php index c1e405f..fd62b03 100644 --- a/apply_form.php +++ b/apply_form.php @@ -20,13 +20,15 @@ defined('MOODLE_INTERNAL') || die(); -require_once("$CFG->libdir/formslib.php"); +require_once($CFG->libdir.'/formslib.php'); +require_once($CFG->dirroot.'/user/editlib.php'); +require_once($CFG->dirroot.'/user/profile/lib.php'); class enrol_apply_apply_form extends moodleform { protected $instance; /** - * Overriding this function to get unique form id for multiple self enrolments + * Overriding this function to get unique form id for multiple apply enrolments * * @return string form identifier */ @@ -36,7 +38,8 @@ class enrol_apply_apply_form extends moodleform { } public function definition() { - global $DB; + global $USER; + $mform = $this->_form; $instance = $this->_customdata; $this->instance = $instance; @@ -47,33 +50,20 @@ class enrol_apply_apply_form extends moodleform { $mform->addElement('html', '

'.$instance->customtext1.'

'); $mform->addElement('textarea', 'applydescription', get_string('comment', 'enrol_apply'),'cols="80"'); + $mform->setType('applydescription', PARAM_TEXT); //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($instance->customint1){ - useredit_shared_definition($mform, $editoroptions, $filemanageroptions,$user); + useredit_shared_definition($mform, $editoroptions, $filemanageroptions, $USER); } if($instance->customint2){ - profile_definition($mform, $user->id); + 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); + $mform->setDefaults((array)$USER); $this->add_action_buttons(false, get_string('enrolme', 'enrol_self')); @@ -84,18 +74,5 @@ class enrol_apply_apply_form extends moodleform { $mform->addElement('hidden', 'instance'); $mform->setType('instance', PARAM_INT); $mform->setDefault('instance', $instance->id); - - //$mform->addElement('html',""); - //$mform->addElement('html',''); - //$mform->addElement('html',''); - } - - public function validation($data, $files) { - global $DB, $CFG; - - $errors = parent::validation($data, $files); - $instance = $this->instance; - - return $errors; } -} \ No newline at end of file +} From a986b87d730ec507e99b3d5cf30d7ad75ec6a2b2 Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Wed, 1 Jun 2016 20:16:52 +0200 Subject: [PATCH 27/28] File comments adjusted --- apply_form.php | 32 ++++++++++++++++++-------------- db/access.php | 34 ++++++++++++++++++---------------- db/upgrade.php | 2 +- edit.php | 30 +++++++++++++++++++++--------- edit_form.php | 32 ++++++++++++++++++++++---------- lib.php | 34 +++++++++++++++++++++++----------- manage.php | 30 +++++++++++++++++++++--------- manage_table.php | 4 ++-- renderer.php | 3 +-- settings.php | 31 ++++++++++++++++++++++--------- version.php | 33 +++++++++++++++++++-------------- 11 files changed, 168 insertions(+), 97 deletions(-) diff --git a/apply_form.php b/apply_form.php index fd62b03..93a6f1e 100644 --- a/apply_form.php +++ b/apply_form.php @@ -1,21 +1,25 @@ . /** - * ************************************************************************* - * * Apply Enrol ** - * ************************************************************************* - * @copyright emeneo.com ** - * @link emeneo.com ** - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** - * ************************************************************************* - * ************************************************************************ -*/ -/** - * Apply enrol plugin implementation. - * - * @package enrol - * @copyright 2010 Petr Skoda {@link http://skodak.org} + * @package enrol_apply + * @copyright emeneo.com (http://emeneo.com/) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @author emeneo.com (http://emeneo.com/) + * @author Johannes Burk */ defined('MOODLE_INTERNAL') || die(); diff --git a/db/access.php b/db/access.php index d5609ef..d3c75d9 100644 --- a/db/access.php +++ b/db/access.php @@ -1,23 +1,25 @@ . /** - * ************************************************************************* - * * Apply Enrol ** - * ************************************************************************* - * @copyright emeneo.com ** - * @link emeneo.com ** - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** - * ************************************************************************* - * ************************************************************************ -*/ - -/** - * Capabilities for apply enrolment plugin. - * - * @package enrol - * @subpackage apply - * @copyright 2010 Petr Skoda {@link http://skodak.org} + * @package enrol_apply + * @copyright emeneo.com (http://emeneo.com/) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @author emeneo.com (http://emeneo.com/) + * @author Johannes Burk */ defined('MOODLE_INTERNAL') || die(); diff --git a/db/upgrade.php b/db/upgrade.php index c402af8..8587679 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -16,7 +16,7 @@ /** * @package enrol_apply - * @copyright emeneo.com + * @copyright emeneo.com (http://emeneo.com/) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @author Johannes Burk */ diff --git a/edit.php b/edit.php index ae033a3..2875f27 100644 --- a/edit.php +++ b/edit.php @@ -1,15 +1,27 @@ . /** - * ************************************************************************* - * * Apply Enrol ** - * ************************************************************************* - * @copyright emeneo.com ** - * @link emeneo.com ** - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** - * ************************************************************************* - * ************************************************************************ -*/ + * @package enrol_apply + * @copyright emeneo.com (http://emeneo.com/) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @author emeneo.com (http://emeneo.com/) + * @author Johannes Burk + */ + require('../../config.php'); require_once('edit_form.php'); diff --git a/edit_form.php b/edit_form.php index bc0cc1c..0572c74 100644 --- a/edit_form.php +++ b/edit_form.php @@ -1,15 +1,27 @@ . /** - * ************************************************************************* - * * Apply Enrol ** - * ************************************************************************* - * @copyright emeneo.com ** - * @link emeneo.com ** - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** - * ************************************************************************* - * ************************************************************************ -*/ + * @package enrol_apply + * @copyright emeneo.com (http://emeneo.com/) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @author emeneo.com (http://emeneo.com/) + * @author Johannes Burk + */ + defined('MOODLE_INTERNAL') || die(); require_once($CFG->libdir.'/formslib.php'); @@ -29,7 +41,7 @@ class enrol_apply_edit_form extends moodleform { $options = array(1 => get_string('yes'), 0 => 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) { diff --git a/lib.php b/lib.php index cb84b2d..b5fb0d3 100644 --- a/lib.php +++ b/lib.php @@ -1,16 +1,28 @@ . + /** - * ************************************************************************* - * * Apply Enrol ** - * ************************************************************************* - * @copyright emeneo.com ** - * @link emeneo.com ** - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** - * ************************************************************************* - * ************************************************************************ -*/ - -/** User participation in course is suspended (used in user_enrolments->status) */ + * @package enrol_apply + * @copyright emeneo.com (http://emeneo.com/) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @author emeneo.com (http://emeneo.com/) + * @author Johannes Burk + */ + +/** The user is put onto a waiting list and therefore the enrolment not active (used in user_enrolments->status) */ define('ENROL_APPLY_USER_WAIT', 2); class enrol_apply_plugin extends enrol_plugin { diff --git a/manage.php b/manage.php index e7f3413..7179eb5 100644 --- a/manage.php +++ b/manage.php @@ -1,14 +1,26 @@ . + /** - * ************************************************************************* - * * Apply Enrol ** - * ************************************************************************* - * @copyright emeneo.com ** - * @link emeneo.com ** - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** - * ************************************************************************* - * ************************************************************************ -*/ + * @package enrol_apply + * @copyright emeneo.com (http://emeneo.com/) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @author emeneo.com (http://emeneo.com/) + * @author Johannes Burk + */ require_once ('../../config.php'); require_once($CFG->dirroot.'/enrol/apply/lib.php'); diff --git a/manage_table.php b/manage_table.php index 68044b0..adece8a 100644 --- a/manage_table.php +++ b/manage_table.php @@ -17,9 +17,9 @@ /** * * @package enrol_apply - * @copyright 2016 Johannes Burk + * @copyright 2016 sudile GbR (http://www.sudile.com) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * + * @author Johannes Burk */ defined('MOODLE_INTERNAL') || die(); diff --git a/renderer.php b/renderer.php index b9681a8..13e1e4e 100644 --- a/renderer.php +++ b/renderer.php @@ -17,14 +17,13 @@ /** * * @package enrol_apply - * @copyright 2015 sudile GbR (http://www.sudile.com) + * @copyright 2016 sudile GbR (http://www.sudile.com) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @author Johannes Burk */ defined('MOODLE_INTERNAL') || die(); - class enrol_apply_renderer extends plugin_renderer_base { public function manage_page($table, $manageurl) { echo $this->header(); diff --git a/settings.php b/settings.php index 61d9053..cbe9ae2 100644 --- a/settings.php +++ b/settings.php @@ -1,14 +1,27 @@ . + /** - * ************************************************************************* - * * Apply Enrol ** - * ************************************************************************* - * @copyright emeneo.com ** - * @link emeneo.com ** - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** - * ************************************************************************* - * ************************************************************************ -*/ + * @package enrol_apply + * @copyright emeneo.com (http://emeneo.com/) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @author emeneo.com (http://emeneo.com/) + * @author Johannes Burk + */ + defined('MOODLE_INTERNAL') || die(); if ($ADMIN->fulltree) { diff --git a/version.php b/version.php index 4781493..f504dcf 100644 --- a/version.php +++ b/version.php @@ -1,20 +1,25 @@ . + /** - * ************************************************************************* - * * Apply Enrol ** - * ************************************************************************* - * @copyright emeneo.com ** - * @link emeneo.com ** - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** - * ************************************************************************* - * ************************************************************************ -*/ -/** - * Short answer question type version information. - * - * @package enrol apply - * @copyright Emeneo {@link http://www.emeneo.com/} + * @package enrol_apply + * @copyright emeneo.com (http://emeneo.com/) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @author emeneo.com (http://emeneo.com/) + * @author Johannes Burk */ defined('MOODLE_INTERNAL') || die(); From fbb31ec2a0e29d6784384dd7a98609982f0226c3 Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Wed, 1 Jun 2016 20:55:49 +0200 Subject: [PATCH 28/28] Format code (code checker) --- apply_form.php | 10 +-- db/access.php | 3 +- edit.php | 54 +++++++------ edit_form.php | 2 +- lang/ca/enrol_apply.php | 43 ++++++---- lang/de/enrol_apply.php | 32 +++++--- lang/en/enrol_apply.php | 34 +++++--- lang/en_us/en_us_enrol_apply.php | 32 +++++--- lang/es/enrol_apply.php | 47 ++++++----- lang/it/enrol_apply.php | 33 +++++--- lang/pt_br/enrol_apply.php | 51 +++++++----- lang/zh_cn/enrol_apply.php | 31 ++++--- lib.php | 133 ++++++++++++++++++------------- manage.php | 10 +-- manage_table.php | 17 ++-- renderer.php | 30 +++++-- settings.php | 14 ++-- unenrolself.php | 15 ++-- 18 files changed, 356 insertions(+), 235 deletions(-) diff --git a/apply_form.php b/apply_form.php index 93a6f1e..33c2029 100644 --- a/apply_form.php +++ b/apply_form.php @@ -53,22 +53,22 @@ class enrol_apply_apply_form extends moodleform { $mform->addElement('header', 'selfheader', $heading); $mform->addElement('html', '

'.$instance->customtext1.'

'); - $mform->addElement('textarea', 'applydescription', get_string('comment', 'enrol_apply'),'cols="80"'); + $mform->addElement('textarea', 'applydescription', get_string('comment', 'enrol_apply'), 'cols="80"'); $mform->setType('applydescription', PARAM_TEXT); - //user profile + // User profile... $editoroptions = $filemanageroptions = null; - if($instance->customint1){ + if ($instance->customint1) { useredit_shared_definition($mform, $editoroptions, $filemanageroptions, $USER); } - if($instance->customint2){ + if ($instance->customint2) { profile_definition($mform, $USER->id); } $mform->setDefaults((array)$USER); - + $this->add_action_buttons(false, get_string('enrolme', 'enrol_self')); $mform->addElement('hidden', 'id'); diff --git a/db/access.php b/db/access.php index d3c75d9..364b4a4 100644 --- a/db/access.php +++ b/db/access.php @@ -36,8 +36,7 @@ $capabilities = array( ) ), - /** - * Enrolment approval. + /* Enrolment approval. * If granted on CONTEXT_SYSTEM level it allows approval for all courses * at Site Administration -> Courses -> Manage enrolment applications. */ diff --git a/edit.php b/edit.php index 2875f27..1cf82c2 100644 --- a/edit.php +++ b/edit.php @@ -26,18 +26,18 @@ require('../../config.php'); require_once('edit_form.php'); $courseid = required_param('courseid', PARAM_INT); -$instanceid = optional_param('id', 0, PARAM_INT); // instanceid +$instanceid = optional_param('id', 0, PARAM_INT); -$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST); -$context = context_course::instance($course->id, MUST_EXIST); +$course = get_course($courseid); +$context = context_course::instance($course->id, MUST_EXIST); require_login($course); require_capability('enrol/apply:config', $context); -$PAGE->set_url('/enrol/apply/edit.php', array('courseid'=>$course->id, 'id'=>$instanceid)); +$PAGE->set_url('/enrol/apply/edit.php', array('courseid' => $course->id, 'id' => $instanceid)); $PAGE->set_pagelayout('admin'); -$return = new moodle_url('/enrol/instances.php', array('id'=>$course->id)); +$return = new moodle_url('/enrol/instances.php', array('id' => $course->id)); if (!enrol_is_enabled('apply')) { redirect($return); } @@ -45,42 +45,48 @@ if (!enrol_is_enabled('apply')) { $plugin = enrol_get_plugin('apply'); if ($instanceid) { - $instance = $DB->get_record('enrol', array('courseid'=>$course->id, 'enrol'=>'apply', 'id'=>$instanceid), '*', MUST_EXIST); + $instance = $DB->get_record( + 'enrol', + array( + 'courseid' => $course->id, + 'enrol' => 'apply', + 'id' => $instanceid), + '*', MUST_EXIST); } else { require_capability('moodle/course:enrolconfig', $context); - // no instance yet, we have to add new instance - navigation_node::override_active_url(new moodle_url('/enrol/instances.php', array('id'=>$course->id))); + // No instance yet, we have to add new instance. + navigation_node::override_active_url(new moodle_url('/enrol/instances.php', array('id' => $course->id))); $instance = (object)$plugin->get_instance_defaults(); $instance->id = null; $instance->courseid = $course->id; } -$mform = new enrol_apply_edit_form(NULL, array($instance, $plugin, $context)); +$mform = new enrol_apply_edit_form(null, array($instance, $plugin, $context)); if ($mform->is_cancelled()) { redirect($return); } else if ($data = $mform->get_data()) { if ($instance->id) { - $instance->status = $data->status; - $instance->name = $data->name; - $instance->customtext1 = $data->customtext1; - $instance->customint1 = $data->customint1; - $instance->customint2 = $data->customint2; - $instance->customint3 = $data->customint3; - $instance->roleid = $data->roleid; - $instance->timemodified = time(); + $instance->status = $data->status; + $instance->name = $data->name; + $instance->customtext1 = $data->customtext1; + $instance->customint1 = $data->customint1; + $instance->customint2 = $data->customint2; + $instance->customint3 = $data->customint3; + $instance->roleid = $data->roleid; + $instance->timemodified = time(); $DB->update_record('enrol', $instance); } else { $fields = array( - 'status' =>$data->status, - 'name' =>$data->name, - 'roleid' =>$data->roleid, - 'customint1' =>$data->customint1, - 'customint2' =>$data->customint2, - 'customint3' =>$data->customint3, - 'customtext1' =>$data->customtext1); + 'status' => $data->status, + 'name' => $data->name, + 'roleid' => $data->roleid, + 'customint1' => $data->customint1, + 'customint2' => $data->customint2, + 'customint3' => $data->customint3, + 'customtext1' => $data->customtext1); $plugin->add_instance($course, $fields); } diff --git a/edit_form.php b/edit_form.php index 0572c74..649a100 100644 --- a/edit_form.php +++ b/edit_form.php @@ -28,7 +28,7 @@ require_once($CFG->libdir.'/formslib.php'); class enrol_apply_edit_form extends moodleform { - function definition() { + protected function definition() { $mform = $this->_form; list($instance, $plugin, $context) = $this->_customdata; diff --git a/lang/ca/enrol_apply.php b/lang/ca/enrol_apply.php index 5c2a903..88151dd 100644 --- a/lang/ca/enrol_apply.php +++ b/lang/ca/enrol_apply.php @@ -1,14 +1,25 @@ . + +/** + * @package enrol_apply + * @copyright emeneo.com (http://emeneo.com/) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + // The name of your plugin. Displayed on admin menus. $string['enrolname'] = 'Inscripció prèvia aprovació'; $string['pluginname'] = 'Inscripció prèvia aprovació'; @@ -26,7 +37,7 @@ $string['confirmusers'] = 'Confirmar inscripcions'; $string['coursename'] = 'Curs'; $string['applyuser'] = 'Nom / Cognom'; $string['applyusermail'] = 'Correu electrònic'; -$string['applydate'] = 'Data d\'inscripció'; +$string['applydate'] = 'Data d\'inscripció'; $string['btnconfirm'] = 'Confirmar'; $string['btncancel'] = 'Cancel·lar'; $string['enrolusers'] = 'Inscriure usuaris'; @@ -34,10 +45,10 @@ $string['enrolusers'] = 'Inscriure usuaris'; $string['status'] = 'Permet inscripció prèvia aprovació'; $string['confirmenrol'] = 'Gestionar sol·licituds'; -$string['apply:config'] = 'Configurar instàncies d\'Inscripció prèvia aprovació'; // Needs more insight -$string['apply:manageapplications'] = 'Gestionar la Inscripció prèvia aprovació'; // Needs more insight -$string['apply:unenrol'] = 'Cancel·lar usuaris del curs'; // Needs more insight - +$string['apply:config'] = 'Configurar instàncies d\'Inscripció prèvia aprovació'; // Needs more insight. +$string['apply:manageapplications'] = 'Gestionar la Inscripció prèvia aprovació'; // Needs more insight. +$string['apply:unenrol'] = 'Cancel·lar usuaris del curs'; // Needs more insight. + $string['notification'] = 'Sol·licitud d\'inscripció enviada correctament.

Rebràs una notificació per correu electrònic un cop estigui confirmada la inscripció.'; $string['sendmailtoteacher'] = 'Enviar notificacions per correu als professors'; @@ -48,5 +59,3 @@ $string['comment'] = 'Comentari'; $string['applymanage'] = 'Gestionar inscripcions'; $string['status_desc'] = 'Allow course access of internally enrolled users.'; - -?> \ No newline at end of file diff --git a/lang/de/enrol_apply.php b/lang/de/enrol_apply.php index 91f042c..ba59bdb 100644 --- a/lang/de/enrol_apply.php +++ b/lang/de/enrol_apply.php @@ -1,14 +1,25 @@ . + /** - * ************************************************************************* - * * Apply Enrol ** - * ************************************************************************* - * @copyright emeneo.com ** - * @link emeneo.com ** - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** - * ************************************************************************* - * ************************************************************************ -*/ + * @package enrol_apply + * @copyright emeneo.com (http://emeneo.com/) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + // The name of your plugin. Displayed on admin menus. $string['enrolname'] = 'Bestätigung der Kurseinschreibung'; $string['pluginname'] = 'Bestätigung der Kurseinschreibung'; @@ -42,7 +53,7 @@ $string['confirmenrol'] = 'Einschreibeanfragen bearbeiten'; $string['apply:config'] = 'Einschreibungsbelegstellen anlegen'; $string['apply:manageapplications'] = 'Einschreibungsanfragen verwalten'; $string['apply:unenrol'] = 'Benutzer aus dem Kurs entfernen'; - + $string['notification'] = 'Einschreibungsantrag wurde erfolgreich gesendet..

Sie werden via Mail informiert, sobald Ihre Einschreibung bestätigt wurde.'; $string['sendmailtoteacher'] = 'Sende eine Hinweis-E-Mail an den Trainer'; @@ -51,4 +62,3 @@ $string['editdescription'] = 'Beschreibung anpassen'; $string['applymanage'] = 'Manage enrolment applications'; $string['status_desc'] = 'Kurszugriff für intern eingeschriebene Nutzer/innen erlauben.'; -?> \ No newline at end of file diff --git a/lang/en/enrol_apply.php b/lang/en/enrol_apply.php index cb7cbb1..9eb56d3 100644 --- a/lang/en/enrol_apply.php +++ b/lang/en/enrol_apply.php @@ -1,14 +1,27 @@ . + /** - * ************************************************************************* - * * Apply Enrol ** - * ************************************************************************* - * @copyright emeneo.com ** - * @link emeneo.com ** - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** - * ************************************************************************* - * ************************************************************************ -*/ + * @package enrol_apply + * @copyright emeneo.com (http://emeneo.com/) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @author emeneo.com (http://emeneo.com/) + * @author Johannes Burk + */ + // The name of your plug-in. Displayed on admin menus. $string['enrolname'] = 'Course enrol confirmation'; $string['pluginname'] = 'Course enrol confirmation'; @@ -60,10 +73,8 @@ $string['apply:manageapplications'] = 'Manage apply enrolment'; $string['apply:unenrol'] = 'Cancel users from the course'; $string['apply:unenrolself'] = 'Cancel self from the course'; - $string['notification'] = 'Enrolment application successfully sent.

You will be informed by email when your enrolment has been confirmed.'; - $string['mailtoteacher_suject'] = 'New Enrolment request!'; $string['editdescription'] = 'Textarea description'; $string['comment'] = 'Comment'; @@ -74,4 +85,3 @@ $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'; -?> diff --git a/lang/en_us/en_us_enrol_apply.php b/lang/en_us/en_us_enrol_apply.php index 08da6af..e4ac997 100644 --- a/lang/en_us/en_us_enrol_apply.php +++ b/lang/en_us/en_us_enrol_apply.php @@ -1,14 +1,25 @@ . + /** - * ************************************************************************* - * * Apply enrol ** - * ************************************************************************* - * @copyright emeneo.com ** - * @link emeneo.com ** - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** - * ************************************************************************* - * ************************************************************************ -*/ + * @package enrol_apply + * @copyright emeneo.com (http://emeneo.com/) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + // The name of your plug-in. Displayed on admin menus. $string['enrollname'] = 'Course enrollment confirmation'; $string['pluginname'] = 'Course enrollment confirmation'; @@ -38,7 +49,7 @@ $string['apply:config'] = 'Configure apply enroll instances'; $string['apply:manageapplications'] = 'Manage apply enrollment'; $string['apply:unenroll'] = 'Cancel users from the course'; $string['apply:unenrollapply'] = 'Cancel self from the course'; - + $string['notification'] = 'Enrolllment application successfully sent.

You will be informed by email when your enrollment has been confirmed.'; $string['sendmailtoteacher'] = 'Send email notification to teachers'; @@ -49,4 +60,3 @@ $string['comment'] = 'Comment'; $string['applymanage'] = 'Manage enrollment applications'; $string['status_desc'] = 'Allow course access of internally enrolled users.'; -?> \ No newline at end of file diff --git a/lang/es/enrol_apply.php b/lang/es/enrol_apply.php index e88807b..b183828 100644 --- a/lang/es/enrol_apply.php +++ b/lang/es/enrol_apply.php @@ -1,18 +1,29 @@ . + +/** + * @package enrol_apply + * @copyright emeneo.com (http://emeneo.com/) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + // The name of your plugin. Displayed on admin menus. $string['enrolname'] = 'Matrículas solicitadas'; $string['pluginname'] = 'Matrículas solicitadas'; -$string['pluginname_desc'] = 'With this plugin users can apply to a course and a teacher have to comfirm before the user gets enroled.'; // needs to be translated +$string['pluginname_desc'] = 'With this plugin users can apply to a course and a teacher have to comfirm before the user gets enroled.'; // Needs to be translated. $string['confirmmailsubject'] = 'Asunto del correo de confirmación'; $string['confirmmailcontent'] = 'Contenido del correo de confirmación'; @@ -26,7 +37,7 @@ $string['confirmusers'] = 'Confirmar matrículas'; $string['coursename'] = 'Curso'; $string['applyuser'] = 'Nombre / Apellido'; $string['applyusermail'] = 'Correo electrónico'; -$string['applydate'] = 'Fecha de solicitud'; // Enrol date -> Fecha de matriculación +$string['applydate'] = 'Fecha de solicitud'; // Enrol date -> Fecha de matriculación. $string['btnconfirm'] = 'Confirmar'; $string['btncancel'] = 'Cancelar'; $string['enrolusers'] = 'Matricular usuarios'; @@ -34,10 +45,10 @@ $string['enrolusers'] = 'Matricular usuarios'; $string['status'] = 'Aceptar matriculación tras aprobación'; $string['confirmenrol'] = 'Gestionar solicitudes'; -$string['apply:config'] = 'Configurar instancias de matrículas solicitadas'; // Needs more insight -$string['apply:manageapplications'] = 'Gestionar matrículas solicitadas'; // Needs more insight -$string['apply:unenrol'] = 'Cancelar usuarios del curso'; // Needs more insight - +$string['apply:config'] = 'Configurar instancias de matrículas solicitadas'; // Needs more insight. +$string['apply:manageapplications'] = 'Gestionar matrículas solicitadas'; // Needs more insight. +$string['apply:unenrol'] = 'Cancelar usuarios del curso'; // Needs more insight. + $string['notification'] = 'Solicitud de matriculación enviada correctamente.

Será notificado por correo electrónico en cuanto se confirme su matriculación.'; $string['sendmailtoteacher'] = 'Enviar notificaciones por correo a los profesores'; @@ -47,6 +58,4 @@ $string['editdescription'] = 'Descripción del área de texto'; $string['comment'] = 'Comentario'; $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. diff --git a/lang/it/enrol_apply.php b/lang/it/enrol_apply.php index 56ac011..64f69b0 100644 --- a/lang/it/enrol_apply.php +++ b/lang/it/enrol_apply.php @@ -1,14 +1,25 @@ . + /** - * ************************************************************************* - * * Apply Enrol ** - * ************************************************************************* - * @copyright emeneo.com ** - * @link emeneo.com ** - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** - * ************************************************************************* - * ************************************************************************ -*/ + * @package enrol_apply + * @copyright emeneo.com (http://emeneo.com/) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + // The name of your plugin. Displayed on admin menus. $string['enrolname'] = 'Conferma di iscrizione al corso'; $string['pluginname'] = 'Conferma di iscrizione al corso'; @@ -38,7 +49,7 @@ $string['apply:config'] = 'Configura le istanze del plugin'; $string['apply:manageapplications'] = 'Gestisci le richieste di iscrizione'; $string['apply:unenrol'] = 'Cancella gli utenti dal corso'; $string['apply:unenrolself'] = 'Permetti all\'utente di disiscriversi dal corso'; - + $string['notification'] = 'Richiesta di iscrizione al corso correttamente inviata.

Verrai informato via email appena la tua richiesta di iscrizione viene confermata. Se vuoi iscriverti ad altri corsi, premi sul "catalogo dei corsi" sul top menu.'; $string['sendmailtoteacher'] = 'Manda email di notifica agli insegnanti'; @@ -49,5 +60,3 @@ $string['comment'] = 'Commento'; $string['applymanage'] = 'Gestisci richieste di iscrizione'; $string['status_desc'] = 'Permette l\'accesso al corso agli utenti iscritti internamente.'; - -?> \ No newline at end of file diff --git a/lang/pt_br/enrol_apply.php b/lang/pt_br/enrol_apply.php index 08fe0fb..7e5a65c 100644 --- a/lang/pt_br/enrol_apply.php +++ b/lang/pt_br/enrol_apply.php @@ -1,18 +1,29 @@ . + +/** + * @package enrol_apply + * @copyright emeneo.com (http://emeneo.com/) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + // The name of your plugin. Displayed on admin menus. $string['enrolname'] = 'Matrículas solicitadas'; $string['pluginname'] = 'Matrículas solicitadas'; -$string['pluginname_desc'] = 'With this plugin users can apply to a course and a teacher have to comfirm before the user gets enroled.'; // needs to be translated +$string['pluginname_desc'] = 'With this plugin users can apply to a course and a teacher have to comfirm before the user gets enroled.'; // Needs to be translated. $string['confirmmailsubject'] = 'Assunto do e-mail de confirmação'; $string['confirmmailcontent'] = 'Conteúdo do e-mail de confirmação'; @@ -26,7 +37,7 @@ $string['confirmusers'] = 'Confirmar matrículas'; $string['coursename'] = 'Curso'; $string['applyuser'] = 'Nome / Sobrenome'; $string['applyusermail'] = 'E-mail'; -$string['applydate'] = 'Data de solicitação'; // Enrol date -> Fecha de matriculación +$string['applydate'] = 'Data de solicitação'; // Enrol date -> Fecha de matriculación. $string['btnconfirm'] = 'Confirmar'; $string['btncancel'] = 'Cancelar'; $string['enrolusers'] = 'Matricular usuários'; @@ -34,17 +45,15 @@ $string['enrolusers'] = 'Matricular usuários'; $string['status'] = 'Aceitar matrícula após aprovação'; $string['confirmenrol'] = 'Gerenciar solicitações'; -$string['apply:config'] = 'Configurar instâncias de matrículas solicitadas'; // Needs more insight -$string['apply:manageapplications'] = 'Gerenciar matrículas solicitadas'; // Needs more insight -$string['apply:unenrol'] = 'Cancelar usuários do curso'; // Needs more insight - +$string['apply:config'] = 'Configurar instâncias de matrículas solicitadas'; // Needs more insight. +$string['apply:manageapplications'] = 'Gerenciar matrículas solicitadas'; // Needs more insight. +$string['apply:unenrol'] = 'Cancelar usuários do curso'; // Needs more insight. + $string['notification'] = 'Solicitação de matrícula enviada com sucesso.

Você será notificado por e-mail quando a sua matrícula for confirmada.'; $string['sendmailtoteacher'] = 'Enviar e-mail de notificação para professores'; $string['mailtoteacher_suject'] = 'Nova solicitação de inscrição!'; -$string['editdescription'] = 'Descrição'; -$string['applymanage'] = 'Manage enrolment applications'; // needs to be translated - -$string['status_desc'] = 'Allow course access of internally enrolled users.'; // needs to be translated +$string['editdescription'] = 'Descrição'; +$string['applymanage'] = 'Manage enrolment applications'; // Needs to be translated. -?> \ No newline at end of file +$string['status_desc'] = 'Allow course access of internally enrolled users.'; // Needs to be translated. diff --git a/lang/zh_cn/enrol_apply.php b/lang/zh_cn/enrol_apply.php index faccad8..b5c26dd 100644 --- a/lang/zh_cn/enrol_apply.php +++ b/lang/zh_cn/enrol_apply.php @@ -1,14 +1,25 @@ . + /** - * ************************************************************************* - * * Apply Enrol ** - * ************************************************************************* - * @copyright emeneo.com ** - * @link emeneo.com ** - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** - * ************************************************************************* - * ************************************************************************ -*/ + * @package enrol_apply + * @copyright emeneo.com (http://emeneo.com/) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + // The name of your plug-in. Displayed on admin menus. $string['enrolname'] = '选课确认'; $string['pluginname'] = '选课确认'; @@ -39,7 +50,6 @@ $string['apply:manageapplications'] = '管理选课申请'; $string['apply:unenrol'] = '从课程中取消用户的选课'; $string['apply:unenrolself'] = '从课程中取消自身的选课'; - $string['notification'] = '选课申请已发送成功

申请通过后您会收到邮件通知。'; $string['sendmailtoteacher'] = '向教师发送邮件通知'; @@ -50,4 +60,3 @@ $string['comment'] = '评论'; $string['applymanage'] = '管理选课申请'; $string['status_desc'] = '允许内部选课的用户进入课程'; -?> diff --git a/lib.php b/lib.php index b5fb0d3..5cf85ab 100644 --- a/lib.php +++ b/lib.php @@ -26,11 +26,12 @@ define('ENROL_APPLY_USER_WAIT', 2); class enrol_apply_plugin extends enrol_plugin { + /** - * Add new instance of enrol plugin with default settings. - * @param object $course - * @return int id of new instance - */ + * Add new instance of enrol plugin with default settings. + * @param object $course + * @return int id of new instance + */ public function add_default_instance($course) { $fields = $this->get_instance_defaults(); return $this->add_instance($course, $fields); @@ -48,28 +49,28 @@ class enrol_apply_plugin extends enrol_plugin { * @return moodle_url page url */ public function get_newinstance_link($courseid) { - $context = context_course::instance($courseid, MUST_EXIST); + $context = context_course::instance($courseid, MUST_EXIST); if (!has_capability('moodle/course:enrolconfig', $context) or !has_capability('enrol/apply:config', $context)) { - return NULL; + return null; } - return new moodle_url('/enrol/apply/edit.php', array('courseid'=>$courseid)); + return new moodle_url('/enrol/apply/edit.php', array('courseid' => $courseid)); } public function enrol_page_hook(stdClass $instance) { global $CFG, $OUTPUT, $SESSION, $USER, $DB; if (isguestuser()) { - // can not enrol guest!! + // Can not enrol guest! return null; } - if ($DB->record_exists('user_enrolments', array('userid'=>$USER->id, 'enrolid'=>$instance->id))) { + if ($DB->record_exists('user_enrolments', array('userid' => $USER->id, 'enrolid' => $instance->id))) { return $OUTPUT->notification(get_string('notification', 'enrol_apply'), 'notifysuccess'); } require_once("$CFG->dirroot/enrol/apply/apply_form.php"); - $form = new enrol_apply_apply_form(NULL, $instance); + $form = new enrol_apply_apply_form(null, $instance); if ($data = $form->get_data()) { // Only process when form submission is for this instance (multi instance support). @@ -79,7 +80,12 @@ class enrol_apply_plugin extends enrol_plugin { $roleid = $instance->roleid; $this->enrol_user($instance, $USER->id, $roleid, $timestart, $timeend, ENROL_USER_SUSPENDED); - $userenrolment = $DB->get_record('user_enrolments', array('userid' => $USER->id, 'enrolid' => $instance->id), 'id', MUST_EXIST); + $userenrolment = $DB->get_record( + 'user_enrolments', + array( + 'userid' => $USER->id, + 'enrolid' => $instance->id), + 'id', MUST_EXIST); $applicationinfo = new stdClass(); $applicationinfo->userenrolmentid = $userenrolment->id; $applicationinfo->comment = $data->applydescription; @@ -102,54 +108,59 @@ class enrol_apply_plugin extends enrol_plugin { if ($instance->enrol !== 'apply') { throw new coding_exception('invalid enrol instance!'); } - $context = context_course::instance($instance->courseid); + $context = context_course::instance($instance->courseid); $icons = array(); if (has_capability('enrol/apply:config', $context)) { - $editlink = new moodle_url("/enrol/apply/edit.php", array('courseid'=>$instance->courseid, 'id'=>$instance->id)); - $icons[] = $OUTPUT->action_icon($editlink, new pix_icon('t/edit', get_string('edit'), 'core', array('class' => 'iconsmall'))); + $editlink = new moodle_url("/enrol/apply/edit.php", array('courseid' => $instance->courseid, 'id' => $instance->id)); + $icons[] = $OUTPUT->action_icon($editlink, new pix_icon( + 't/edit', + get_string('edit'), + 'core', + array('class' => 'iconsmall'))); } if (has_capability('enrol/apply:manageapplications', $context)) { - $managelink = new moodle_url("/enrol/apply/manage.php", array('id'=>$instance->id)); - $icons[] = $OUTPUT->action_icon($managelink, new pix_icon('i/users', get_string('confirmenrol', 'enrol_apply'), 'core', array('class'=>'iconsmall'))); + $managelink = new moodle_url("/enrol/apply/manage.php", array('id' => $instance->id)); + $icons[] = $OUTPUT->action_icon($managelink, new pix_icon( + 'i/users', + get_string('confirmenrol', 'enrol_apply'), + 'core', + array('class' => 'iconsmall'))); } return $icons; } - /** - * Is it possible to hide/show enrol instance via standard UI? - * - * @param stdClass $instance - * @return bool - */ + /** + * Is it possible to hide/show enrol instance via standard UI? + * @param stdClass $instance + * @return bool + */ public function can_hide_show_instance($instance) { $context = context_course::instance($instance->courseid); return has_capability('enrol/apply:config', $context); } - + /** - * Is it possible to delete enrol instance via standard UI? - * - * @param stdClass $instance - * @return bool - */ - + * Is it possible to delete enrol instance via standard UI? + * + * @param stdClass $instance + * @return bool + */ public function can_delete_instance($instance) { $context = context_course::instance($instance->courseid); return has_capability('enrol/apply:config', $context); } - - + /** - * Sets up navigation entries. - * - * @param stdClass $instancesnode - * @param stdClass $instance - * @return void - */ + * Sets up navigation entries. + * + * @param stdClass $instancesnode + * @param stdClass $instance + * @return void + */ public function add_course_navigation($instancesnode, stdClass $instance) { if ($instance->enrol !== 'apply') { throw new coding_exception('Invalid enrol instance type!'); @@ -157,7 +168,7 @@ class enrol_apply_plugin extends enrol_plugin { $context = context_course::instance($instance->courseid); if (has_capability('enrol/apply:config', $context)) { - $managelink = new moodle_url('/enrol/apply/edit.php', array('courseid'=>$instance->courseid, 'id'=>$instance->id)); + $managelink = new moodle_url('/enrol/apply/edit.php', array('courseid' => $instance->courseid, 'id' => $instance->id)); $instancesnode->add($this->get_instance_name($instance), $managelink, navigation_node::TYPE_SETTING); } } @@ -195,10 +206,9 @@ class enrol_apply_plugin extends enrol_plugin { return $fields; } - function confirmEnrolment($enrols){ + public function confirm_enrolment($enrols) { global $DB; - foreach ($enrols as $enrol){ - // $userenrolment = $DB->get_record('user_enrolments', array('id' => $enrol), '*', MUST_EXIST); + foreach ($enrols as $enrol) { $userenrolment = $DB->get_record_select( 'user_enrolments', 'id = :id AND (status = :enrolusersuspended OR status = :enrolapplyuserwait)', @@ -226,10 +236,13 @@ class enrol_apply_plugin extends enrol_plugin { } } - function waitEnrolment($enrols){ + public function wait_enrolment($enrols) { global $DB; - foreach ($enrols as $enrol){ - $userenrolment = $DB->get_record('user_enrolments', array('id' => $enrol, 'status' => ENROL_USER_SUSPENDED), '*', IGNORE_MISSING); + foreach ($enrols as $enrol) { + $userenrolment = $DB->get_record( + 'user_enrolments', + array('id' => $enrol, 'status' => ENROL_USER_SUSPENDED), + '*', IGNORE_MISSING); if ($userenrolment != null) { $instance = $DB->get_record('enrol', array('id' => $userenrolment->enrolid, 'enrol' => 'apply'), '*', MUST_EXIST); @@ -249,9 +262,9 @@ class enrol_apply_plugin extends enrol_plugin { } } - function cancelEnrolment($enrols){ + public function cancel_enrolment($enrols) { global $DB; - foreach ($enrols as $enrol){ + foreach ($enrols as $enrol) { $userenrolment = $DB->get_record_select( 'user_enrolments', 'id = :id AND (status = :enrolusersuspended OR status = :enrolapplyuserwait)', @@ -279,19 +292,19 @@ class enrol_apply_plugin extends enrol_plugin { } } - function send_mail_to_applicant($instance, $userid, $subject, $body) { + private function send_mail_to_applicant($instance, $userid, $subject, $body) { global $DB; global $CFG; $course = get_course($instance->courseid); $user = core_user::get_user($userid); - $body = $this->updateMailContent($body, $course, $user); + $body = $this->update_mail_content($body, $course, $user); $contact = core_user::get_support_user(); email_to_user($user, $contact, $subject, html_to_text($body), $body); } - function send_application_notification($instance, $userid, $data) { + private function send_application_notification($instance, $userid, $data) { global $CFG, $PAGE; $renderer = $PAGE->get_renderer('enrol_apply'); @@ -323,7 +336,13 @@ class enrol_apply_plugin extends enrol_plugin { $teachers = get_role_users($editingteacherrole->id, $context); $manageurl = new moodle_url("/enrol/apply/manage.php", array('id' => $instance->id)); - $body = $renderer->application_notification_mail_body($course, $user, $manageurl, $data->applydescription, $standarduserfields, $extrauserfields); + $body = $renderer->application_notification_mail_body( + $course, + $user, + $manageurl, + $data->applydescription, + $standarduserfields, + $extrauserfields); foreach ($teachers as $teacher) { email_to_user($teacher, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body); } @@ -337,21 +356,27 @@ class enrol_apply_plugin extends enrol_plugin { $managers = get_role_users($managerrole->id, $context); $manageurl = new moodle_url('/enrol/apply/manage.php'); - $body = $renderer->application_notification_mail_body($course, $user, $manageurl, $data->applydescription, $standarduserfields, $extrauserfields); + $body = $renderer->application_notification_mail_body( + $course, + $user, + $manageurl, + $data->applydescription, + $standarduserfields, + $extrauserfields); foreach ($managers as $manager) { email_to_user($manager, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body); } } } - function updateMailContent($content, $course, $user) { + private function update_mail_content($content, $course, $user) { $replace = array( 'firstname' => $user->firstname, 'content' => format_string($course->fullname), 'lastname' => $user->lastname, 'username' => $user->username); - foreach ($replace as $key=>$val) { - $content = str_replace("{".$key."}",$val,$content); + foreach ($replace as $key => $val) { + $content = str_replace('{' . $key . '}', $val, $content); } return $content; } diff --git a/manage.php b/manage.php index 7179eb5..5dc7365 100644 --- a/manage.php +++ b/manage.php @@ -22,7 +22,7 @@ * @author Johannes Burk */ -require_once ('../../config.php'); +require_once('../../config.php'); require_once($CFG->dirroot.'/enrol/apply/lib.php'); require_once($CFG->dirroot.'/enrol/apply/manage_table.php'); require_once($CFG->dirroot.'/enrol/apply/renderer.php'); @@ -38,7 +38,7 @@ if ($id == null) { require_capability('enrol/apply:manageapplications', $context); $pageheading = get_string('confirmusers', 'enrol_apply'); } else { - $instance = $DB->get_record('enrol', array('id'=>$id, 'enrol'=>'apply'), '*', MUST_EXIST); + $instance = $DB->get_record('enrol', array('id' => $id, 'enrol' => 'apply'), '*', MUST_EXIST); require_course_login($instance->courseid); $course = get_course($instance->courseid); $context = context_course::instance($course->id, MUST_EXIST); @@ -60,11 +60,11 @@ $PAGE->requires->css('/enrol/apply/style.css'); if ($userenrolments != null) { $enrolapply = enrol_get_plugin('apply'); if (optional_param('confirm', false, PARAM_BOOL)) { - $enrolapply->confirmEnrolment($userenrolments); + $enrolapply->confirm_enrolment($userenrolments); } else if (optional_param('wait', false, PARAM_BOOL)) { - $enrolapply->waitEnrolment($userenrolments); + $enrolapply->wait_enrolment($userenrolments); } else if (optional_param('cancel', false, PARAM_BOOL)) { - $enrolapply->cancelEnrolment($userenrolments); + $enrolapply->cancel_enrolment($userenrolments); } redirect($manageurl); } diff --git a/manage_table.php b/manage_table.php index adece8a..3c98dd4 100644 --- a/manage_table.php +++ b/manage_table.php @@ -46,12 +46,13 @@ class enrol_apply_manage_table extends table_sql { } $this->set_sql( - 'ue.id AS userenrolmentid, ue.userid, ue.status AS enrolstatus, ue.timecreated AS applydate, ai.comment AS applycomment, u.*, c.fullname as course', + 'ue.id AS userenrolmentid, ue.userid, ue.status AS enrolstatus, ue.timecreated AS applydate, + ai.comment AS applycomment, u.*, c.fullname as course', "{user_enrolments} AS ue - LEFT JOIN {enrol_apply_applicationinfo} AS ai ON ai.userenrolmentid = ue.id - JOIN {user} AS u ON u.id = ue.userid - JOIN {enrol} AS e ON e.id = ue.enrolid - JOIN {course} AS c ON c.id = e.courseid", + LEFT JOIN {enrol_apply_applicationinfo} ai ON ai.userenrolmentid = ue.id + JOIN {user} u ON u.id = ue.userid + JOIN {enrol} e ON e.id = ue.enrolid + JOIN {course} c ON c.id = e.courseid", $sqlwhere, $sqlparams); } @@ -61,7 +62,7 @@ class enrol_apply_manage_table extends table_sql { * @param $row array the data for this row. Note (Johannes): this is actually an object with all sql columns. * @return string added to the class="" attribute of the tr. */ - function get_row_class($row) { + public function get_row_class($row) { if ($row->enrolstatus == 2) { return 'enrol_apply_waitinglist_highlight'; } @@ -73,9 +74,9 @@ class enrol_apply_manage_table extends table_sql { } public function col_fullname($row) { - // $row contains all user fields, see sql query. + // The $row variable contains all user fields, see sql query. global $OUTPUT; - $col = $OUTPUT->user_picture($row, array('popup'=>true)); + $col = $OUTPUT->user_picture($row, array('popup' => true)); $col .= fullname($row); return $col; } diff --git a/renderer.php b/renderer.php index 13e1e4e..7d95c76 100644 --- a/renderer.php +++ b/renderer.php @@ -41,15 +41,27 @@ class enrol_apply_renderer extends plugin_renderer_base { } public function manage_form($table, $manageurl) { - echo html_writer::start_tag('form', array('id' => 'enrol_apply_manage_form', 'method' => 'post', 'action' => $manageurl->out())); + echo html_writer::start_tag('form', array( + 'id' => 'enrol_apply_manage_form', + 'method' => 'post', + 'action' => $manageurl->out())); $this->manage_table($table); echo html_writer::start_tag('p', array('align' => 'center')); - echo html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'confirm', 'value' => get_string('btnconfirm', 'enrol_apply'))); - echo html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'wait', 'value' => get_string('btnwait', 'enrol_apply'))); - echo html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'cancel', 'value' => get_string('btncancel', 'enrol_apply'))); + echo html_writer::empty_tag('input', array( + 'type' => 'submit', + 'name' => 'confirm', + 'value' => get_string('btnconfirm', 'enrol_apply'))); + echo html_writer::empty_tag('input', array( + 'type' => 'submit', + 'name' => 'wait', + 'value' => get_string('btnwait', 'enrol_apply'))); + echo html_writer::empty_tag('input', array( + 'type' => 'submit', + 'name' => 'cancel', + 'value' => get_string('btncancel', 'enrol_apply'))); echo html_writer::end_tag('p'); echo html_writer::end_tag('form'); @@ -78,11 +90,13 @@ class enrol_apply_renderer extends plugin_renderer_base { $table->out(50, true); } - public function application_notification_mail_body($course, $user, $manageurl, $applydescription, $standarduserfields = null, $extrauserfields = null) { + public function application_notification_mail_body( + $course, $user, $manageurl, $applydescription, $standarduserfields = null, $extrauserfields = 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($standarduserfields){ + if ($standarduserfields) { $body .= '

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

'; $body .= '

'. get_string('firstname') .': '.$standarduserfields->firstname.'

'; $body .= '

'. get_string('lastname') .': '.$standarduserfields->lastname.'

'; @@ -110,7 +124,7 @@ class enrol_apply_renderer extends plugin_renderer_base { $body .= '

'. get_string('address') .': '.$standarduserfields->address.'

'; } - if($extrauserfields){ + if ($extrauserfields) { foreach ($extrauserfields as $key => $value) { $body .= '

'. $key .': '.$value.'

'; } @@ -120,4 +134,4 @@ class enrol_apply_renderer extends plugin_renderer_base { return $body; } -} \ No newline at end of file +} diff --git a/settings.php b/settings.php index cbe9ae2..f58eb01 100644 --- a/settings.php +++ b/settings.php @@ -26,9 +26,9 @@ defined('MOODLE_INTERNAL') || die(); if ($ADMIN->fulltree) { - $settings->add(new admin_setting_heading('enrol_apply_enrolname','',get_string('pluginname_desc', 'enrol_apply'))); - - // Confirm mail settings. + $settings->add(new admin_setting_heading('enrol_apply_enrolname', '', get_string('pluginname_desc', 'enrol_apply'))); + + // Confirm mail settings... $settings->add(new admin_setting_heading( 'enrol_apply_confirmmail', get_string('confirmmail_heading', 'enrol_apply'), @@ -66,7 +66,7 @@ if ($ADMIN->fulltree) { null, PARAM_RAW)); - // Cancel mail settings + // Cancel mail settings... $settings->add(new admin_setting_heading( 'enrol_apply_cancelmail', get_string('cancelmail_heading', 'enrol_apply'), @@ -85,7 +85,7 @@ if ($ADMIN->fulltree) { null, PARAM_RAW)); - // Notification settings. + // Notification settings... $settings->add(new admin_setting_heading( 'enrol_apply_notify', get_string('notify_heading', 'enrol_apply'), @@ -101,7 +101,7 @@ if ($ADMIN->fulltree) { '', 0)); - // Enrol instance defaults. + // Enrol instance defaults... $settings->add(new admin_setting_heading('enrol_manual_defaults', get_string('enrolinstancedefaults', 'admin'), get_string('enrolinstancedefaults_desc', 'admin'))); @@ -132,7 +132,7 @@ if ($ADMIN->fulltree) { } } -if ($hassiteconfig) { // needs this condition or there is error on login page +if ($hassiteconfig) { // Needs this condition or there is error on login page. $ADMIN->add('courses', new admin_externalpage('enrol_apply', get_string('applymanage', 'enrol_apply'), new moodle_url('/enrol/apply/manage.php'))); diff --git a/unenrolself.php b/unenrolself.php index 77a875e..4cf6021 100644 --- a/unenrolself.php +++ b/unenrolself.php @@ -30,8 +30,8 @@ require('../../config.php'); $enrolid = required_param('enrolid', PARAM_INT); $confirm = optional_param('confirm', 0, PARAM_BOOL); -$instance = $DB->get_record('enrol', array('id'=>$enrolid, 'enrol'=>'apply'), '*', MUST_EXIST); -$course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST); +$instance = $DB->get_record('enrol', array('id' => $enrolid, 'enrol' => 'apply'), '*', MUST_EXIST); +$course = $DB->get_record('course', array('id' => $instance->courseid), '*', MUST_EXIST); $context = context_course::instance($course->id, MUST_EXIST); require_login(); @@ -44,10 +44,10 @@ $plugin = enrol_get_plugin('apply'); // Security defined inside following function. if (!$plugin->get_unenrolself_link($instance)) { - redirect(new moodle_url('/course/view.php', array('id'=>$course->id))); + redirect(new moodle_url('/course/view.php', array('id' => $course->id))); } -$PAGE->set_url('/enrol/apply/unenrolself.php', array('enrolid'=>$instance->id)); +$PAGE->set_url('/enrol/apply/unenrolself.php', array('enrolid' => $instance->id)); $PAGE->set_title($plugin->get_instance_name($instance)); if ($confirm and confirm_sesskey()) { @@ -57,8 +57,9 @@ if ($confirm and confirm_sesskey()) { } echo $OUTPUT->header(); -$yesurl = new moodle_url($PAGE->url, array('confirm'=>1, 'sesskey'=>sesskey())); -$nourl = new moodle_url('/course/view.php', array('id'=>$course->id)); -$message = get_string('unenrolselfconfirm', 'enrol_self', format_string($course->fullname)); //I leave the unenrolselfconfirm message because it fits perfectly +$yesurl = new moodle_url($PAGE->url, array('confirm' => 1, 'sesskey' => sesskey())); +$nourl = new moodle_url('/course/view.php', array('id' => $course->id)); +// I leave the unenrolselfconfirm message because it fits perfectly. +$message = get_string('unenrolselfconfirm', 'enrol_self', format_string($course->fullname)); echo $OUTPUT->confirm($message, $yesurl, $nourl); echo $OUTPUT->footer();