Browse Source

Merge pull request #66 from sudile/dev-refactor

Refactor code
SABERES_37_STABLE
Flotter Totte 9 years ago
parent
commit
decd96843d
  1. 112
      apply.php
  2. 82
      apply_form.php
  3. 66
      db/access.php
  4. 41
      db/install.php
  5. 18
      db/upgrade.php
  6. 70
      edit.php
  7. 40
      edit_form.php
  8. 187
      enroluser.php
  9. 40
      lang/ca/enrol_apply.php
  10. 33
      lang/de/enrol_apply.php
  11. 59
      lang/en/enrol_apply.php
  12. 32
      lang/en_us/en_us_enrol_apply.php
  13. 46
      lang/es/enrol_apply.php
  14. 34
      lang/it/enrol_apply.php
  15. 48
      lang/pt_br/enrol_apply.php
  16. 34
      lang/zh_cn/enrol_apply.php
  17. 551
      lib.php
  18. 157
      locallib.php
  19. 118
      manage.php
  20. 87
      manage_table.php
  21. 137
      renderer.php
  22. 155
      selectlib.php
  23. 143
      settings.php
  24. 3
      style.css
  25. 27
      unenrolself.php
  26. 98
      unenroluser.php
  27. 36
      version.php

112
apply.php

@ -1,112 +0,0 @@
<?php
/**
* *************************************************************************
* * Apply Enrol **
* *************************************************************************
* @copyright emeneo.com **
* @link emeneo.com **
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **
* *************************************************************************
* ************************************************************************
*/
require ('../../config.php');
require_once($CFG->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 '<form id="frmenrol" method="post" action="apply.php?id=' . $id . '&enrolid=' . $enrolid . '">';
echo '<input type="hidden" id="type" name="type" value="confirm">';
echo '<table class="generalbox editcourse boxaligncenter"><tr class="header">';
echo '<th class="header" scope="col">&nbsp;</th>';
echo '<th class="header" scope="col">' . get_string ( 'coursename', 'enrol_apply' ) . '</th>';
echo '<th class="header" scope="col">&nbsp;</th>';
echo '<th class="header" scope="col">' . get_string ( 'applyuser', 'enrol_apply' ) . '</th>';
echo '<th class="header" scope="col">' . get_string ( 'applyusermail', 'enrol_apply' ) . '</th>';
echo '<th class="header" scope="col">' . get_string ( 'applydate', 'enrol_apply' ) . '</th>';
echo '<th class="header" scope="col">' . get_string ( 'comment', 'enrol_apply' ) . '</th>';
echo '</tr>';
foreach ( $enrols as $enrol ) {
$picture = get_user_picture($enrol->userid);
if ($enrol->status == 2) {
echo '<tr style="vertical-align: top; background-color: #ccc;">';
} else {
echo '<tr style="vertical-align: top;">';
}
echo '<td><input type="checkbox" name="userenrolments[]" value="' . $enrol->id . '"></td>';
echo '<td>' . format_string($enrol->course) . '</td>';
echo '<td>' . $OUTPUT->render($picture) . '</td>';
echo '<td>'.$enrol->firstname . ' ' . $enrol->lastname.'</td>';
echo '<td>' . $enrol->email . '</td>';
echo '<td>' . date ( "Y-m-d", $enrol->timecreated ) . '</td>';
echo '<td>' . htmlspecialchars($applicationinfo[$enrol->id]->comment) . '</td>';
echo '</tr>';
}
echo '</table>';
echo '<p align="center">';
echo '<input type="button" value="' . get_string ( 'btnconfirm', 'enrol_apply' ) . '" onclick="doSubmit(\'confirm\');">';
echo '<input type="button" value="' . get_string ( 'btnwait', 'enrol_apply' ) . '" onclick="doSubmit(\'wait\');">';
echo '<input type="button" value="' . get_string ( 'btncancel', 'enrol_apply' ) . '" onclick="doSubmit(\'cancel\');">';
echo '</p>';
echo '</form>';
echo '<script>function doSubmit(type){
document.getElementById("type").value=type;
document.getElementById("frmenrol").submit();
}</script>';
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);
}

82
apply_form.php

@ -0,0 +1,82 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @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 <johannes.burk@sudile.com>
*/
defined('MOODLE_INTERNAL') || die();
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 apply enrolments
*
* @return string form identifier
*/
protected function get_form_identifier() {
$formid = $this->_customdata->id.'_'.get_class($this);
return $formid;
}
public function definition() {
global $USER;
$mform = $this->_form;
$instance = $this->_customdata;
$this->instance = $instance;
$plugin = enrol_get_plugin('apply');
$heading = $plugin->get_instance_name($instance);
$mform->addElement('header', 'selfheader', $heading);
$mform->addElement('html', '<p>'.$instance->customtext1.'</p>');
$mform->addElement('textarea', 'applydescription', get_string('comment', 'enrol_apply'), 'cols="80"');
$mform->setType('applydescription', PARAM_TEXT);
// User profile...
$editoroptions = $filemanageroptions = null;
if ($instance->customint1) {
useredit_shared_definition($mform, $editoroptions, $filemanageroptions, $USER);
}
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');
$mform->setType('id', PARAM_INT);
$mform->setDefault('id', $instance->courseid);
$mform->addElement('hidden', 'instance');
$mform->setType('instance', PARAM_INT);
$mform->setDefault('instance', $instance->id);
}
}

66
db/access.php

@ -1,41 +1,33 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* ************************************************************************* * @package enrol_apply
* * Apply Enrol ** * @copyright emeneo.com (http://emeneo.com/)
* *************************************************************************
* @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}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author emeneo.com (http://emeneo.com/)
* @author Johannes Burk <johannes.burk@sudile.com>
*/ */
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$capabilities = array( $capabilities = array(
/* Add, edit or remove manual enrol instance. */
'enrol/apply:config' => array( 'enrol/apply:config' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW,
)
),
'enrol/apply:manage' => array(
'captype' => 'write', 'captype' => 'write',
'contextlevel' => CONTEXT_COURSE, 'contextlevel' => CONTEXT_COURSE,
'archetypes' => array( 'archetypes' => array(
@ -44,16 +36,11 @@ $capabilities = array(
) )
), ),
//is this still necessary? /* Enrolment approval.
'enrol/apply:unenrolapply' => array( * If granted on CONTEXT_SYSTEM level it allows approval for all courses
'captype' => 'write', * at Site Administration -> Courses -> Manage enrolment applications.
'contextlevel' => CONTEXT_COURSE, */
'archetypes' => array( 'enrol/apply:manageapplications' => array(
'student' => CAP_ALLOW,
)
),
'enrol/apply:enrol' => array(
'captype' => 'write', 'captype' => 'write',
'contextlevel' => CONTEXT_COURSE, 'contextlevel' => CONTEXT_COURSE,
'archetypes' => array( 'archetypes' => array(
@ -62,6 +49,7 @@ $capabilities = array(
) )
), ),
/* Unenrol a user */
'enrol/apply:unenrol' => array( 'enrol/apply:unenrol' => array(
'captype' => 'write', 'captype' => 'write',
'contextlevel' => CONTEXT_COURSE, 'contextlevel' => CONTEXT_COURSE,
@ -71,6 +59,7 @@ $capabilities = array(
) )
), ),
/* Allow a user to unenrol himself */
'enrol/apply:unenrolself' => array( 'enrol/apply:unenrolself' => array(
'captype' => 'write', 'captype' => 'write',
'contextlevel' => CONTEXT_COURSE, 'contextlevel' => CONTEXT_COURSE,
@ -78,7 +67,4 @@ $capabilities = array(
'student' => CAP_ALLOW, 'student' => CAP_ALLOW,
) )
), ),
); );

41
db/install.php

@ -1,41 +0,0 @@
<?php
/**
* *************************************************************************
* * Apply Enrol **
* *************************************************************************
* @copyright emeneo.com **
* @link emeneo.com **
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **
* *************************************************************************
* ************************************************************************
*/
/**
* apply enrol plugin installation script
*
* @package enrol
* @subpackage apply
* @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();
function xmldb_enrol_apply_install() {
global $CFG, $DB;
// migrate welcome message
if (isset($CFG->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');
}
}

18
db/upgrade.php

@ -16,7 +16,7 @@
/** /**
* @package enrol_apply * @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 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Johannes Burk <johannes.burk@sudile.com> * @author Johannes Burk <johannes.burk@sudile.com>
*/ */
@ -51,6 +51,22 @@ function xmldb_enrol_apply_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2016012801, 'enrol', 'apply'); 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; return true;
} }

70
edit.php

@ -1,31 +1,43 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* ************************************************************************* * @package enrol_apply
* * Apply Enrol ** * @copyright emeneo.com (http://emeneo.com/)
* ************************************************************************* * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright emeneo.com ** * @author emeneo.com (http://emeneo.com/)
* @link emeneo.com ** * @author Johannes Burk <johannes.burk@sudile.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** */
* *************************************************************************
* ************************************************************************
*/
require('../../config.php'); require('../../config.php');
require_once('edit_form.php'); require_once('edit_form.php');
$courseid = required_param('courseid', PARAM_INT); $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); $course = get_course($courseid);
$context = context_course::instance($course->id, MUST_EXIST); $context = context_course::instance($course->id, MUST_EXIST);
require_login($course); require_login($course);
require_capability('enrol/apply:config', $context); 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'); $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')) { if (!enrol_is_enabled('apply')) {
redirect($return); redirect($return);
} }
@ -33,17 +45,23 @@ if (!enrol_is_enabled('apply')) {
$plugin = enrol_get_plugin('apply'); $plugin = enrol_get_plugin('apply');
if ($instanceid) { 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 { } else {
require_capability('moodle/course:enrolconfig', $context); require_capability('moodle/course:enrolconfig', $context);
// no instance yet, we have to add new instance // No instance yet, we have to add new instance.
navigation_node::override_active_url(new moodle_url('/enrol/instances.php', array('id'=>$course->id))); navigation_node::override_active_url(new moodle_url('/enrol/instances.php', array('id' => $course->id)));
$instance = (object)$plugin->get_instance_defaults(); $instance = (object)$plugin->get_instance_defaults();
$instance->id = null; $instance->id = null;
$instance->courseid = $course->id; $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()) { if ($mform->is_cancelled()) {
redirect($return); redirect($return);
@ -62,11 +80,13 @@ if ($mform->is_cancelled()) {
} else { } else {
$fields = array( $fields = array(
'status' =>$data->status, 'status' => $data->status,
'name' =>$data->name, 'name' => $data->name,
'roleid' =>$data->roleid, 'roleid' => $data->roleid,
'customint3' =>$data->customint3, 'customint1' => $data->customint1,
'customtext1' =>$data->customtext1); 'customint2' => $data->customint2,
'customint3' => $data->customint3,
'customtext1' => $data->customtext1);
$plugin->add_instance($course, $fields); $plugin->add_instance($course, $fields);
} }
@ -76,7 +96,5 @@ if ($mform->is_cancelled()) {
$PAGE->set_heading(format_string($course->fullname)); $PAGE->set_heading(format_string($course->fullname));
$PAGE->set_title(get_string('pluginname', 'enrol_apply')); $PAGE->set_title(get_string('pluginname', 'enrol_apply'));
echo $OUTPUT->header(); $renderer = $PAGE->get_renderer('enrol_apply');
echo $OUTPUT->heading(get_string('pluginname', 'enrol_apply')); $renderer->edit_page($mform);
$mform->display();
echo $OUTPUT->footer();

40
edit_form.php

@ -1,22 +1,34 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* ************************************************************************* * @package enrol_apply
* * Apply Enrol ** * @copyright emeneo.com (http://emeneo.com/)
* ************************************************************************* * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright emeneo.com ** * @author emeneo.com (http://emeneo.com/)
* @link emeneo.com ** * @author Johannes Burk <johannes.burk@sudile.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** */
* *************************************************************************
* ************************************************************************
*/
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/formslib.php'); require_once($CFG->libdir.'/formslib.php');
class enrol_self_edit_form extends moodleform { class enrol_apply_edit_form extends moodleform {
function definition() { protected function definition() {
$mform = $this->_form; $mform = $this->_form;
list($instance, $plugin, $context) = $this->_customdata; list($instance, $plugin, $context) = $this->_customdata;
@ -26,10 +38,10 @@ class enrol_self_edit_form extends moodleform {
$mform->addElement('text', 'name', get_string('custominstancename', 'enrol')); $mform->addElement('text', 'name', get_string('custominstancename', 'enrol'));
$mform->setType('name', PARAM_TEXT); $mform->setType('name', PARAM_TEXT);
$options = array(ENROL_INSTANCE_ENABLED => get_string('yes'), $options = array(1 => get_string('yes'),
ENROL_INSTANCE_DISABLED => get_string('no')); 0 => get_string('no'));
$mform->addElement('select', 'status', get_string('status', 'enrol_apply'), $options); $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')); $mform->setDefault('status', $plugin->get_config('status'));
if ($instance->id) { if ($instance->id) {

187
enroluser.php

@ -1,187 +0,0 @@
<?php
/**
* *************************************************************************
* * Apply Enrol **
* *************************************************************************
* @copyright emeneo.com **
* @link emeneo.com **
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **
* *************************************************************************
* ************************************************************************
*/
require('../../config.php');
require_once($CFG->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 "<pre>";print_r($instance);exit();
$enrol_manual->enrol_user($instance, $adduser->id, $roleid, $timestart, $timeend);
// Deprecated fixed by Shiro <gigashiro@gmail.com>
//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 <gigashiro@gmail.com>
//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);
?>
<form id="assignform" method="post" action="<?php echo $PAGE->url ?>"><div>
<input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" />
<table summary="" class="roleassigntable generaltable generalbox boxaligncenter" cellspacing="0">
<tr>
<td id="existingcell">
<p><label for="removeselect"><?php print_string('enrolledusers', 'enrol'); ?></label></p>
<?php $currentuserselector->display() ?>
</td>
<td id="buttonscell">
<div id="addcontrols">
<input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().'&nbsp;'.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
<div class="enroloptions">
<p><label for="roleid"><?php print_string('assignrole', 'enrol_manual') ?></label><br />
<?php echo html_writer::select($roles, 'roleid', $roleid, false); ?></p>
<p><label for="extendperiod"><?php print_string('enrolperiod', 'enrol') ?></label><br />
<?php echo html_writer::select($periodmenu, 'extendperiod', $defaultperiod, $unlimitedperiod); ?></p>
<p><label for="extendbase"><?php print_string('startingfrom') ?></label><br />
<?php echo html_writer::select($basemenu, 'extendbase', $extendbase, false); ?></p>
</div>
</div>
<div id="removecontrols">
<input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').'&nbsp;'.$OUTPUT->rarrow(); ?>" title="<?php print_string('remove'); ?>" />
</div>
</td>
<td id="potentialcell">
<p><label for="addselect"><?php print_string('enrolcandidates', 'enrol'); ?></label></p>
<?php $potentialuserselector->display() ?>
</td>
</tr>
</table>
</div></form>
<?php
echo $OUTPUT->footer();

40
lang/ca/enrol_apply.php

@ -1,14 +1,25 @@
<?php <?php
/** // This file is part of Moodle - http://moodle.org/
* ************************************************************************* //
* * Apply Enrol ** // Moodle is free software: you can redistribute it and/or modify
* ************************************************************************* // it under the terms of the GNU General Public License as published by
* @copyright emeneo.com ** // the Free Software Foundation, either version 3 of the License, or
* @link emeneo.com ** // (at your option) any later version.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** //
* ************************************************************************* // Moodle is distributed in the hope that it will be useful,
* ************************************************************************ // but WITHOUT ANY WARRANTY; without even the implied warranty of
*/ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @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. // The name of your plugin. Displayed on admin menus.
$string['enrolname'] = 'Inscripció prèvia aprovació'; $string['enrolname'] = 'Inscripció prèvia aprovació';
$string['pluginname'] = 'Inscripció prèvia aprovació'; $string['pluginname'] = 'Inscripció prèvia aprovació';
@ -34,10 +45,9 @@ $string['enrolusers'] = 'Inscriure usuaris';
$string['status'] = 'Permet inscripció prèvia aprovació'; $string['status'] = 'Permet inscripció prèvia aprovació';
$string['confirmenrol'] = 'Gestionar sol·licituds'; $string['confirmenrol'] = 'Gestionar sol·licituds';
$string['apply:config'] = 'Configurar instàncies d\'Inscripció prèvia aprovació'; // Needs more insight $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['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'] = '<b>Sol·licitud d\'inscripció enviada correctament</b>. <br/><br/>Rebràs una notificació per correu electrònic un cop estigui confirmada la inscripció.'; $string['notification'] = '<b>Sol·licitud d\'inscripció enviada correctament</b>. <br/><br/>Rebràs una notificació per correu electrònic un cop estigui confirmada la inscripció.';
@ -49,5 +59,3 @@ $string['comment'] = 'Comentari';
$string['applymanage'] = 'Gestionar inscripcions'; $string['applymanage'] = 'Gestionar inscripcions';
$string['status_desc'] = 'Allow course access of internally enrolled users.'; $string['status_desc'] = 'Allow course access of internally enrolled users.';
?>

33
lang/de/enrol_apply.php

@ -1,14 +1,25 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* ************************************************************************* * @package enrol_apply
* * Apply Enrol ** * @copyright emeneo.com (http://emeneo.com/)
* ************************************************************************* * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright emeneo.com ** */
* @link emeneo.com **
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **
* *************************************************************************
* ************************************************************************
*/
// The name of your plugin. Displayed on admin menus. // The name of your plugin. Displayed on admin menus.
$string['enrolname'] = 'Bestätigung der Kurseinschreibung'; $string['enrolname'] = 'Bestätigung der Kurseinschreibung';
$string['pluginname'] = 'Bestätigung der Kurseinschreibung'; $string['pluginname'] = 'Bestätigung der Kurseinschreibung';
@ -40,9 +51,8 @@ $string['status'] = 'Bestätigung der Kurseinschreibung erlauben';
$string['confirmenrol'] = 'Einschreibeanfragen bearbeiten'; $string['confirmenrol'] = 'Einschreibeanfragen bearbeiten';
$string['apply:config'] = 'Einschreibungsbelegstellen anlegen'; $string['apply:config'] = 'Einschreibungsbelegstellen anlegen';
$string['apply:manage'] = 'Einschreibungsanfragen verwalten'; $string['apply:manageapplications'] = 'Einschreibungsanfragen verwalten';
$string['apply:unenrol'] = 'Benutzer aus dem Kurs entfernen'; $string['apply:unenrol'] = 'Benutzer aus dem Kurs entfernen';
$string['apply:unenrolapply'] = 'Sich selbst aus dem Kurs entfernen';
$string['notification'] = '<b>Einschreibungsantrag wurde erfolgreich gesendet.</b>. <br/><br/>Sie werden via Mail informiert, sobald Ihre Einschreibung bestätigt wurde.'; $string['notification'] = '<b>Einschreibungsantrag wurde erfolgreich gesendet.</b>. <br/><br/>Sie werden via Mail informiert, sobald Ihre Einschreibung bestätigt wurde.';
@ -52,4 +62,3 @@ $string['editdescription'] = 'Beschreibung anpassen';
$string['applymanage'] = 'Manage enrolment applications'; $string['applymanage'] = 'Manage enrolment applications';
$string['status_desc'] = 'Kurszugriff für intern eingeschriebene Nutzer/innen erlauben.'; $string['status_desc'] = 'Kurszugriff für intern eingeschriebene Nutzer/innen erlauben.';
?>

59
lang/en/enrol_apply.php

@ -1,29 +1,58 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* ************************************************************************* * @package enrol_apply
* * Apply Enrol ** * @copyright emeneo.com (http://emeneo.com/)
* ************************************************************************* * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright emeneo.com ** * @author emeneo.com (http://emeneo.com/)
* @link emeneo.com ** * @author Johannes Burk <johannes.burk@sudile.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** */
* *************************************************************************
* ************************************************************************
*/
// The name of your plug-in. Displayed on admin menus. // The name of your plug-in. Displayed on admin menus.
$string['enrolname'] = 'Course enrol confirmation'; $string['enrolname'] = 'Course enrol confirmation';
$string['pluginname'] = '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['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'] = 'Confirmation email subject';
$string['confirmmailsubject_desc'] = '';
$string['confirmmailcontent'] = 'Confirmation email content'; $string['confirmmailcontent'] = 'Confirmation email content';
$string['confirmmailcontent_desc'] = 'Please use the following special marks to replace email content with data from Moodle.<br/>{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'] = 'Waiting list mail subject';
$string['waitmailsubject_desc'] = '';
$string['waitmailcontent'] = 'Waiting list mail content'; $string['waitmailcontent'] = 'Waiting list mail content';
$string['waitmailcontent_desc'] = 'Please use the following special marks to replace email content with data from Moodle.<br/>{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'] = 'Cancelation email subject';
$string['cancelmailsubject_desc'] = '';
$string['cancelmailcontent'] = 'Cancelation email content'; $string['cancelmailcontent'] = 'Cancelation email content';
$string['confirmmailcontent_desc'] = 'Please use the following special marks to replace email content with data from Moodle.<br/>{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.<br/>{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.<br/>{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.<br/>{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'] = 'Enrol Confirm';
$string['confirmusers_desc'] = 'Users in gray colored rows are on the waiting list.'; $string['confirmusers_desc'] = 'Users in gray colored rows are on the waiting list.';
@ -40,17 +69,12 @@ $string['status'] = 'Allow Course enrol confirmation';
$string['confirmenrol'] = 'Manage application'; $string['confirmenrol'] = 'Manage application';
$string['apply:config'] = 'Configure apply enrol instances'; $string['apply:config'] = 'Configure apply enrol instances';
$string['apply:enrol'] = 'Enrol users'; $string['apply:manageapplications'] = 'Manage apply enrolment';
$string['apply:manage'] = 'Manage apply enrolment';
$string['apply:unenrol'] = 'Cancel users from the course'; $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'; $string['apply:unenrolself'] = 'Cancel self from the course';
$string['notification'] = '<b>Enrolment application successfully sent</b>. <br/><br/>You will be informed by email when your enrolment has been confirmed.'; $string['notification'] = '<b>Enrolment application successfully sent</b>. <br/><br/>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['mailtoteacher_suject'] = 'New Enrolment request!';
$string['editdescription'] = 'Textarea description'; $string['editdescription'] = 'Textarea description';
$string['comment'] = 'Comment'; $string['comment'] = 'Comment';
@ -61,4 +85,3 @@ $string['user_profile'] = 'User Profile';
$string['show_standard_user_profile'] = 'Show standard user profile fields on enrolment screen'; $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'; $string['show_extra_user_profile'] = 'Show extra user profile fields on enrolment screen';
?>

32
lang/en_us/en_us_enrol_apply.php

@ -1,14 +1,25 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* ************************************************************************* * @package enrol_apply
* * Apply enrol ** * @copyright emeneo.com (http://emeneo.com/)
* ************************************************************************* * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright emeneo.com ** */
* @link 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. // The name of your plug-in. Displayed on admin menus.
$string['enrollname'] = 'Course enrollment confirmation'; $string['enrollname'] = 'Course enrollment confirmation';
$string['pluginname'] = 'Course enrollment confirmation'; $string['pluginname'] = 'Course enrollment confirmation';
@ -35,7 +46,7 @@ $string['status'] = 'Allow course enroll confirmation';
$string['confirmenroll'] = 'Manage application'; $string['confirmenroll'] = 'Manage application';
$string['apply:config'] = 'Configure apply enroll instances'; $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:unenroll'] = 'Cancel users from the course';
$string['apply:unenrollapply'] = 'Cancel self from the course'; $string['apply:unenrollapply'] = 'Cancel self from the course';
@ -49,4 +60,3 @@ $string['comment'] = 'Comment';
$string['applymanage'] = 'Manage enrollment applications'; $string['applymanage'] = 'Manage enrollment applications';
$string['status_desc'] = 'Allow course access of internally enrolled users.'; $string['status_desc'] = 'Allow course access of internally enrolled users.';
?>

46
lang/es/enrol_apply.php

@ -1,18 +1,29 @@
<?php <?php
/** // This file is part of Moodle - http://moodle.org/
* ************************************************************************* //
* * Apply Enrol ** // Moodle is free software: you can redistribute it and/or modify
* ************************************************************************* // it under the terms of the GNU General Public License as published by
* @copyright emeneo.com ** // the Free Software Foundation, either version 3 of the License, or
* @link emeneo.com ** // (at your option) any later version.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** //
* ************************************************************************* // Moodle is distributed in the hope that it will be useful,
* ************************************************************************ // but WITHOUT ANY WARRANTY; without even the implied warranty of
*/ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @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. // The name of your plugin. Displayed on admin menus.
$string['enrolname'] = 'Matrículas solicitadas'; $string['enrolname'] = 'Matrículas solicitadas';
$string['pluginname'] = '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['confirmmailsubject'] = 'Asunto del correo de confirmación';
$string['confirmmailcontent'] = 'Contenido 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['coursename'] = 'Curso';
$string['applyuser'] = 'Nombre / Apellido'; $string['applyuser'] = 'Nombre / Apellido';
$string['applyusermail'] = 'Correo electrónico'; $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['btnconfirm'] = 'Confirmar';
$string['btncancel'] = 'Cancelar'; $string['btncancel'] = 'Cancelar';
$string['enrolusers'] = 'Matricular usuarios'; $string['enrolusers'] = 'Matricular usuarios';
@ -34,10 +45,9 @@ $string['enrolusers'] = 'Matricular usuarios';
$string['status'] = 'Aceptar matriculación tras aprobación'; $string['status'] = 'Aceptar matriculación tras aprobación';
$string['confirmenrol'] = 'Gestionar solicitudes'; $string['confirmenrol'] = 'Gestionar solicitudes';
$string['apply:config'] = 'Configurar instancias de matrículas solicitadas'; // Needs more insight $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['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'] = '<b>Solicitud de matriculación enviada correctamente</b>. <br/><br/>Será notificado por correo electrónico en cuanto se confirme su matriculación.'; $string['notification'] = '<b>Solicitud de matriculación enviada correctamente</b>. <br/><br/>Será notificado por correo electrónico en cuanto se confirme su matriculación.';
@ -48,6 +58,4 @@ $string['editdescription'] = 'Descripción del área de texto';
$string['comment'] = 'Comentario'; $string['comment'] = 'Comentario';
$string['applymanage'] = 'Gestionar matrículas'; $string['applymanage'] = 'Gestionar matrículas';
$string['status_desc'] = 'Allow course access of internally enrolled users.'; // needs to be translated $string['status_desc'] = 'Allow course access of internally enrolled users.'; // Needs to be translated.
?>

34
lang/it/enrol_apply.php

@ -1,14 +1,25 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* ************************************************************************* * @package enrol_apply
* * Apply Enrol ** * @copyright emeneo.com (http://emeneo.com/)
* ************************************************************************* * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright emeneo.com ** */
* @link emeneo.com **
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **
* *************************************************************************
* ************************************************************************
*/
// The name of your plugin. Displayed on admin menus. // The name of your plugin. Displayed on admin menus.
$string['enrolname'] = 'Conferma di iscrizione al corso'; $string['enrolname'] = 'Conferma di iscrizione al corso';
$string['pluginname'] = 'Conferma di iscrizione al corso'; $string['pluginname'] = 'Conferma di iscrizione al corso';
@ -35,9 +46,8 @@ $string['status'] = 'Permetti la conferma di iscrizione al corso';
$string['confirmenrol'] = 'Gestisci l\'applicazione'; $string['confirmenrol'] = 'Gestisci l\'applicazione';
$string['apply:config'] = 'Configura le istanze del plugin'; $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: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['apply:unenrolself'] = 'Permetti all\'utente di disiscriversi dal corso';
$string['notification'] = '<b>Richiesta di iscrizione al corso correttamente inviata</b>. <br/><br/>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['notification'] = '<b>Richiesta di iscrizione al corso correttamente inviata</b>. <br/><br/>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.';
@ -50,5 +60,3 @@ $string['comment'] = 'Commento';
$string['applymanage'] = 'Gestisci richieste di iscrizione'; $string['applymanage'] = 'Gestisci richieste di iscrizione';
$string['status_desc'] = 'Permette l\'accesso al corso agli utenti iscritti internamente.'; $string['status_desc'] = 'Permette l\'accesso al corso agli utenti iscritti internamente.';
?>

48
lang/pt_br/enrol_apply.php

@ -1,18 +1,29 @@
<?php <?php
/** // This file is part of Moodle - http://moodle.org/
* ************************************************************************* //
* * Apply Enrol ** // Moodle is free software: you can redistribute it and/or modify
* ************************************************************************* // it under the terms of the GNU General Public License as published by
* @copyright emeneo.com ** // the Free Software Foundation, either version 3 of the License, or
* @link emeneo.com ** // (at your option) any later version.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** //
* ************************************************************************* // Moodle is distributed in the hope that it will be useful,
* ************************************************************************ // but WITHOUT ANY WARRANTY; without even the implied warranty of
*/ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @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. // The name of your plugin. Displayed on admin menus.
$string['enrolname'] = 'Matrículas solicitadas'; $string['enrolname'] = 'Matrículas solicitadas';
$string['pluginname'] = '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['confirmmailsubject'] = 'Assunto do e-mail de confirmação';
$string['confirmmailcontent'] = 'Conteúdo 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['coursename'] = 'Curso';
$string['applyuser'] = 'Nome / Sobrenome'; $string['applyuser'] = 'Nome / Sobrenome';
$string['applyusermail'] = 'E-mail'; $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['btnconfirm'] = 'Confirmar';
$string['btncancel'] = 'Cancelar'; $string['btncancel'] = 'Cancelar';
$string['enrolusers'] = 'Matricular usuários'; $string['enrolusers'] = 'Matricular usuários';
@ -34,18 +45,15 @@ $string['enrolusers'] = 'Matricular usuários';
$string['status'] = 'Aceitar matrícula após aprovação'; $string['status'] = 'Aceitar matrícula após aprovação';
$string['confirmenrol'] = 'Gerenciar solicitações'; $string['confirmenrol'] = 'Gerenciar solicitações';
$string['apply:config'] = 'Configurar instâncias de matrículas solicitadas'; // Needs more insight $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['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'] = '<b>Solicitação de matrícula enviada com sucesso</b>. <br/><br/>Você será notificado por e-mail quando a sua matrícula for confirmada.'; $string['notification'] = '<b>Solicitação de matrícula enviada com sucesso</b>. <br/><br/>Você será notificado por e-mail quando a sua matrícula for confirmada.';
$string['sendmailtoteacher'] = 'Enviar e-mail de notificação para professores'; $string['sendmailtoteacher'] = 'Enviar e-mail de notificação para professores';
$string['mailtoteacher_suject'] = 'Nova solicitação de inscrição!'; $string['mailtoteacher_suject'] = 'Nova solicitação de inscrição!';
$string['editdescription'] = 'Descrição'; $string['editdescription'] = 'Descrição';
$string['applymanage'] = 'Manage enrolment applications'; // needs to be translated $string['applymanage'] = 'Manage enrolment applications'; // Needs to be translated.
$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.

34
lang/zh_cn/enrol_apply.php

@ -1,14 +1,25 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* ************************************************************************* * @package enrol_apply
* * Apply Enrol ** * @copyright emeneo.com (http://emeneo.com/)
* ************************************************************************* * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright emeneo.com ** */
* @link 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. // The name of your plug-in. Displayed on admin menus.
$string['enrolname'] = '选课确认'; $string['enrolname'] = '选课确认';
$string['pluginname'] = '选课确认'; $string['pluginname'] = '选课确认';
@ -35,12 +46,10 @@ $string['status'] = '允许选课确认';
$string['confirmenrol'] = '管理申请'; $string['confirmenrol'] = '管理申请';
$string['apply:config'] = '配置选课确认的实例'; $string['apply:config'] = '配置选课确认的实例';
$string['apply:manage'] = '管理选课申请'; $string['apply:manageapplications'] = '管理选课申请';
$string['apply:unenrol'] = '从课程中取消用户的选课'; $string['apply:unenrol'] = '从课程中取消用户的选课';
$string['apply:unenrolapply'] = '从课程中取消自身的选课'; // is this necessary now?
$string['apply:unenrolself'] = '从课程中取消自身的选课'; $string['apply:unenrolself'] = '从课程中取消自身的选课';
$string['notification'] = '<b>选课申请已发送成功</b><br/><br/>申请通过后您会收到邮件通知。'; $string['notification'] = '<b>选课申请已发送成功</b><br/><br/>申请通过后您会收到邮件通知。';
$string['sendmailtoteacher'] = '向教师发送邮件通知'; $string['sendmailtoteacher'] = '向教师发送邮件通知';
@ -51,4 +60,3 @@ $string['comment'] = '评论';
$string['applymanage'] = '管理选课申请'; $string['applymanage'] = '管理选课申请';
$string['status_desc'] = '允许内部选课的用户进入课程'; $string['status_desc'] = '允许内部选课的用户进入课程';
?>

551
lib.php

@ -1,14 +1,30 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* ************************************************************************* * @package enrol_apply
* * Apply Enrol ** * @copyright emeneo.com (http://emeneo.com/)
* ************************************************************************* * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright emeneo.com ** * @author emeneo.com (http://emeneo.com/)
* @link emeneo.com ** * @author Johannes Burk <johannes.burk@sudile.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** */
* *************************************************************************
* ************************************************************************ /** 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 { class enrol_apply_plugin extends enrol_plugin {
/** /**
@ -22,115 +38,68 @@ class enrol_apply_plugin extends enrol_plugin {
} }
public function allow_unenrol(stdClass $instance) { 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; 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) { 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)) { if (!has_capability('moodle/course:enrolconfig', $context) or !has_capability('enrol/apply:config', $context)) {
return NULL; return null;
} }
// multiple instances supported - different roles with different password 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) { public function enrol_page_hook(stdClass $instance) {
global $CFG, $OUTPUT, $SESSION, $USER, $DB; global $CFG, $OUTPUT, $SESSION, $USER, $DB;
if (isguestuser()) { if (isguestuser()) {
// can not enrol guest!! // Can not enrol guest!
return null; 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))) {
//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'); 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()) {
$userInfo = $data; // Only process when form submission is for this instance (multi instance support).
$applydescription = $userInfo->applydescription; if ($data->instance == $instance->id) {
unset($userInfo->applydescription); $timestart = 0;
$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; $timeend = 0;
}
$roleid = $instance->roleid; $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); $userenrolment = $DB->get_record(
'user_enrolments',
array(
'userid' => $USER->id,
'enrolid' => $instance->id),
'id', MUST_EXIST);
$applicationinfo = new stdClass(); $applicationinfo = new stdClass();
$applicationinfo->userenrolmentid = $userenrolment->id; $applicationinfo->userenrolmentid = $userenrolment->id;
$applicationinfo->comment = $applydescription; $applicationinfo->comment = $data->applydescription;
$DB->insert_record('enrol_apply_applicationinfo', $applicationinfo, false); $DB->insert_record('enrol_apply_applicationinfo', $applicationinfo, false);
sendConfirmMailToTeachers($instance, $data, $applydescription);
sendConfirmMailToManagers($instance, $data, $applydescription);
// Deprecated fixed by Shiro <gigashiro@gmail.com> $this->send_application_notification($instance, $USER->id, $data);
//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"); 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) { public function get_action_icons(stdClass $instance) {
@ -144,18 +113,21 @@ class enrol_apply_plugin extends enrol_plugin {
$icons = array(); $icons = array();
if (has_capability('enrol/apply:config', $context)) { if (has_capability('enrol/apply:config', $context)) {
$editlink = new moodle_url("/enrol/apply/edit.php", array('courseid'=>$instance->courseid, 'id'=>$instance->id)); $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'))); $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/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'))); $icons[] = $OUTPUT->action_icon($managelink, new pix_icon(
} 'i/users',
get_string('confirmenrol', 'enrol_apply'),
if (has_capability("enrol/apply:enrol", $context)) { 'core',
$enrollink = new moodle_url("/enrol/apply/enroluser.php", array('enrolid'=>$instance->id)); array('class' => 'iconsmall')));
$icons[] = $OUTPUT->action_icon($enrollink, new pix_icon('t/enrolusers', get_string('enrolusers', 'enrol_apply'), 'core', array('class'=>'iconsmall')));
} }
return $icons; return $icons;
@ -163,7 +135,6 @@ class enrol_apply_plugin extends enrol_plugin {
/** /**
* Is it possible to hide/show enrol instance via standard UI? * Is it possible to hide/show enrol instance via standard UI?
*
* @param stdClass $instance * @param stdClass $instance
* @return bool * @return bool
*/ */
@ -178,13 +149,11 @@ class enrol_apply_plugin extends enrol_plugin {
* @param stdClass $instance * @param stdClass $instance
* @return bool * @return bool
*/ */
public function can_delete_instance($instance) { public function can_delete_instance($instance) {
$context = context_course::instance($instance->courseid); $context = context_course::instance($instance->courseid);
return has_capability('enrol/apply:config', $context); return has_capability('enrol/apply:config', $context);
} }
/** /**
* Sets up navigation entries. * Sets up navigation entries.
* *
@ -199,7 +168,7 @@ class enrol_apply_plugin extends enrol_plugin {
$context = context_course::instance($instance->courseid); $context = context_course::instance($instance->courseid);
if (has_capability('enrol/apply:config', $context)) { 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); $instancesnode->add($this->get_instance_name($instance), $managelink, navigation_node::TYPE_SETTING);
} }
} }
@ -210,13 +179,13 @@ class enrol_apply_plugin extends enrol_plugin {
$instance = $ue->enrolmentinstance; $instance = $ue->enrolmentinstance;
$params = $manager->get_moodlepage()->url->params(); $params = $manager->get_moodlepage()->url->params();
$params['ue'] = $ue->id; $params['ue'] = $ue->id;
if ($this->allow_unenrol($instance) && has_capability("enrol/apply:unenrol", $context)) { if ($this->allow_unenrol_user($instance, $ue) && has_capability("enrol/apply:unenrol", $context)) {
$url = new moodle_url('/enrol/apply/unenroluser.php', $params); $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)); $actions[] = new user_enrolment_action(
} new pix_icon('t/delete', ''),
if ($this->allow_manage($instance) && has_capability("enrol/apply:manage", $context)) { get_string('unenrol', 'enrol'),
$url = new moodle_url('/enrol/apply/editenrolment.php', $params); $url,
$actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, array('class'=>'editenrollink', 'rel'=>$ue->id)); array('class' => 'unenrollink', 'rel' => $ue->id));
} }
return $actions; return $actions;
} }
@ -236,291 +205,179 @@ class enrol_apply_plugin extends enrol_plugin {
return $fields; return $fields;
} }
}
function getAllEnrolment($id = null) { public function confirm_enrolment($enrols) {
global $DB; global $DB;
if ($id) { foreach ($enrols as $enrol) {
$sql = 'SELECT ue.userid,ue.id,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated,ue.status $userenrolment = $DB->get_record_select(
FROM {course} c 'user_enrolments',
JOIN {enrol} e 'id = :id AND (status = :enrolusersuspended OR status = :enrolapplyuserwait)',
ON e.courseid = c.id array(
JOIN {user_enrolments} ue 'id' => $enrol,
ON ue.enrolid = e.id 'enrolusersuspended' => ENROL_USER_SUSPENDED,
JOIN {user} u 'enrolapplyuserwait' => ENROL_APPLY_USER_WAIT),
ON ue.userid = u.id '*',
WHERE ue.status != 0 MUST_EXIST);
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
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;
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){ $instance = $DB->get_record('enrol', array('id' => $userenrolment->enrolid, 'enrol' => 'apply'), '*', MUST_EXIST);
global $DB;
global $CFG;
foreach ($enrols as $enrol){
@$enroluser->id = $enrol;
@$enroluser->status = 2;
if($DB->update_record('user_enrolments',$enroluser)){ // Check privileges.
$info = getRelatedInfo($enrol); $context = context_course::instance($instance->courseid, MUST_EXIST);
sendWaitMail($info); if (!has_capability('enrol/apply:manageapplications', $context)) {
} continue;
} }
}
function cancelEnrolment($enrols){ $this->update_user_enrol($instance, $userenrolment->userid, ENROL_USER_ACTIVE);
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)); $DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol));
sendCancelMail($info);
$subject = get_config('enrol_apply', 'confirmmailsubject');
$body = get_config('enrol_apply', 'confirmmailcontent');
$this->send_mail_to_applicant($instance, $userenrolment->userid, $subject, $body);
} }
} }
}
function sendCancelMail($info){ public function wait_enrolment($enrols) {
global $DB; global $DB;
global $CFG; foreach ($enrols as $enrol) {
$apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'"); $userenrolment = $DB->get_record(
'user_enrolments',
array('id' => $enrol, 'status' => ENROL_USER_SUSPENDED),
'*', IGNORE_MISSING);
$replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); if ($userenrolment != null) {
$body = $apply_setting['cancelmailcontent']->value; $instance = $DB->get_record('enrol', array('id' => $userenrolment->enrolid, 'enrol' => 'apply'), '*', MUST_EXIST);
$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); // Check privileges.
$body = $apply_setting['confirmmailcontent']->value; $context = context_course::instance($instance->courseid, MUST_EXIST);
$body = updateMailContent($body,$replace); if (!has_capability('enrol/apply:manageapplications', $context)) {
$contact = core_user::get_support_user(); continue;
email_to_user($info, $contact, $apply_setting['confirmmailsubject']->value, html_to_text($body), $body); }
}
function sendWaitMail($info){ $this->update_user_enrol($instance, $userenrolment->userid, ENROL_APPLY_USER_WAIT);
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); $subject = get_config('enrol_apply', 'waitmailsubject');
$body = get_config('enrol_apply', 'waitmailcontent'); $body = get_config('enrol_apply', 'waitmailcontent');
$body = updateMailContent($body,$replace); $this->send_mail_to_applicant($instance, $userenrolment->userid, $subject, $body);
$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){ public function cancel_enrolment($enrols) {
global $DB; global $DB;
global $CFG; foreach ($enrols as $enrol) {
global $USER; $userenrolment = $DB->get_record_select(
'user_enrolments',
$courseid = $instance->courseid; 'id = :id AND (status = :enrolusersuspended OR status = :enrolapplyuserwait)',
$instanceid = $instance->id; array(
$apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'"); 'id' => $enrol,
'enrolusersuspended' => ENROL_USER_SUSPENDED,
'enrolapplyuserwait' => ENROL_APPLY_USER_WAIT),
'*',
MUST_EXIST);
$show_standard_user_profile = $show_extra_user_profile = false; $instance = $DB->get_record('enrol', array('id' => $userenrolment->enrolid, 'enrol' => 'apply'), '*', MUST_EXIST);
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 != ''){ // Check privileges.
($instance->customint2 == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false; $context = context_course::instance($instance->courseid, MUST_EXIST);
}else{ if (!has_capability('enrol/apply:manageapplications', $context)) {
($apply_setting['show_extra_user_profile']->value == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false; continue;
} }
if($instance->customint3 == 1){ $this->unenrol_user($instance, $userenrolment->userid);
$course = get_course($courseid); $DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol));
$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 = '<p>'. get_string('coursename', 'enrol_apply') .': '.format_string($course->fullname).'</p>';
$body .= '<p>'. get_string('applyuser', 'enrol_apply') .': '.$USER->firstname.' '.$USER->lastname.'</p>';
$body .= '<p>'. get_string('comment', 'enrol_apply') .': '.$applydescription.'</p>';
if($show_standard_user_profile){
$body .= '<p><strong>'. get_string('user_profile', 'enrol_apply').'</strong></p>';
$body .= '<p>'. get_string('firstname') .': '.$info->firstname.'</p>';
$body .= '<p>'. get_string('lastname') .': '.$info->lastname.'</p>';
$body .= '<p>'. get_string('email') .': '.$info->email.'</p>';
$body .= '<p>'. get_string('city') .': '.$info->city.'</p>';
$body .= '<p>'. get_string('country') .': '.$info->country.'</p>';
$body .= '<p>'. get_string('preferredlanguage') .': '.$info->lang.'</p>';
$body .= '<p>'. get_string('description') .': '.$info->description_editor['text'].'</p>';
$body .= '<p>'. get_string('firstnamephonetic') .': '.$info->firstnamephonetic.'</p>';
$body .= '<p>'. get_string('lastnamephonetic') .': '.$info->lastnamephonetic.'</p>';
$body .= '<p>'. get_string('middlename') .': '.$info->middlename.'</p>';
$body .= '<p>'. get_string('alternatename') .': '.$info->alternatename.'</p>';
$body .= '<p>'. get_string('url') .': '.$info->url.'</p>';
$body .= '<p>'. get_string('icqnumber') .': '.$info->icq.'</p>';
$body .= '<p>'. get_string('skypeid') .': '.$info->skype.'</p>';
$body .= '<p>'. get_string('aimid') .': '.$info->aim.'</p>';
$body .= '<p>'. get_string('yahooid') .': '.$info->yahoo.'</p>';
$body .= '<p>'. get_string('msnid') .': '.$info->msn.'</p>';
$body .= '<p>'. get_string('idnumber') .': '.$info->idnumber.'</p>';
$body .= '<p>'. get_string('institution') .': '.$info->institution.'</p>';
$body .= '<p>'. get_string('department') .': '.$info->department.'</p>';
$body .= '<p>'. get_string('phone') .': '.$info->phone1.'</p>';
$body .= '<p>'. get_string('phone2') .': '.$info->phone2.'</p>';
$body .= '<p>'. get_string('address') .': '.$info->address.'</p>';
}
if($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 .= '<p>'. $key .': '.$value.'</p>';
}
}
$body .= '<p>'. html_writer::link(new moodle_url("/enrol/apply/apply.php", array('id'=>$courseid,'enrolid'=>$instanceid)), get_string('applymanage', 'enrol_apply')).'</p>'; $subject = get_config('enrol_apply', 'cancelmailsubject');
$contact = core_user::get_support_user(); $body = get_config('enrol_apply', 'cancelmailcontent');
$info = $editTeacher; $this->send_mail_to_applicant($instance, $userenrolment->userid, $subject, $body);
$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){ private function send_mail_to_applicant($instance, $userid, $subject, $body) {
global $DB; global $DB;
global $CFG; global $CFG;
global $USER;
$courseid = $instance->courseid; $course = get_course($instance->courseid);
$apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'"); $user = core_user::get_user($userid);
$show_standard_user_profile = $show_extra_user_profile = false; $body = $this->update_mail_content($body, $course, $user);
if($instance->customint1 != ''){ $contact = core_user::get_support_user();
($instance->customint1 == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false; email_to_user($user, $contact, $subject, html_to_text($body), $body);
}else{
($apply_setting['show_standard_user_profile']->value == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false;
} }
if($instance->customint2 != ''){ private function send_application_notification($instance, $userid, $data) {
($instance->customint2 == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false; global $CFG, $PAGE;
}else{
($apply_setting['show_extra_user_profile']->value == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false; $renderer = $PAGE->get_renderer('enrol_apply');
$course = get_course($instance->courseid);
$user = core_user::get_user($userid);
$contact = core_user::get_support_user();
// Include standard user profile fields?
$standarduserfields = null;
if ($instance->customint1) {
$standarduserfields = clone $data;
unset($standarduserfields->applydescription);
} }
if($apply_setting['sendmailtomanager']->value == 1){ // Include extra user profile fields?
$course = get_course($courseid); $extrauserfields = null;
$context = context_system::instance(); if ($instance->customint2) {
$managerType = $DB->get_record('role',array("shortname"=>"manager"));
$managers = $DB->get_records('role_assignments', array('contextid'=>$context->id,'roleid'=>$managerType->id));
foreach($managers as $manager){
$userWithManagerRole = $DB->get_record('user',array('id'=>$manager->userid));
$body = '<p>'. get_string('coursename', 'enrol_apply') .': '.format_string($course->fullname).'</p>';
$body .= '<p>'. get_string('applyuser', 'enrol_apply') .': '.$USER->firstname.' '.$USER->lastname.'</p>';
$body .= '<p>'. get_string('comment', 'enrol_apply') .': '.$applydescription.'</p>';
if($show_standard_user_profile){
$body .= '<p><strong>'. get_string('user_profile', 'enrol_apply').'</strong></p>';
$body .= '<p>'. get_string('firstname') .': '.$info->firstname.'</p>';
$body .= '<p>'. get_string('lastname') .': '.$info->lastname.'</p>';
$body .= '<p>'. get_string('email') .': '.$info->email.'</p>';
$body .= '<p>'. get_string('city') .': '.$info->city.'</p>';
$body .= '<p>'. get_string('country') .': '.$info->country.'</p>';
$body .= '<p>'. get_string('preferredlanguage') .': '.$info->lang.'</p>';
$body .= '<p>'. get_string('description') .': '.$info->description_editor['text'].'</p>';
$body .= '<p>'. get_string('firstnamephonetic') .': '.$info->firstnamephonetic.'</p>';
$body .= '<p>'. get_string('lastnamephonetic') .': '.$info->lastnamephonetic.'</p>';
$body .= '<p>'. get_string('middlename') .': '.$info->middlename.'</p>';
$body .= '<p>'. get_string('alternatename') .': '.$info->alternatename.'</p>';
$body .= '<p>'. get_string('url') .': '.$info->url.'</p>';
$body .= '<p>'. get_string('icqnumber') .': '.$info->icq.'</p>';
$body .= '<p>'. get_string('skypeid') .': '.$info->skype.'</p>';
$body .= '<p>'. get_string('aimid') .': '.$info->aim.'</p>';
$body .= '<p>'. get_string('yahooid') .': '.$info->yahoo.'</p>';
$body .= '<p>'. get_string('msnid') .': '.$info->msn.'</p>';
$body .= '<p>'. get_string('idnumber') .': '.$info->idnumber.'</p>';
$body .= '<p>'. get_string('institution') .': '.$info->institution.'</p>';
$body .= '<p>'. get_string('department') .': '.$info->department.'</p>';
$body .= '<p>'. get_string('phone') .': '.$info->phone1.'</p>';
$body .= '<p>'. get_string('phone2') .': '.$info->phone2.'</p>';
$body .= '<p>'. get_string('address') .': '.$info->address.'</p>';
}
if($show_extra_user_profile){
require_once($CFG->dirroot.'/user/profile/lib.php'); require_once($CFG->dirroot.'/user/profile/lib.php');
$user = $DB->get_record('user',array('id'=>$USER->id));
profile_load_custom_fields($user); profile_load_custom_fields($user);
foreach ($user->profile as $key => $value) { $extrauserfields = $user->profile;
$body .= '<p>'. $key .': '.$value.'</p>';
}
} }
$body .= '<p>'. html_writer::link(new moodle_url('/enrol/apply/manage.php'), get_string('applymanage', 'enrol_apply')).'</p>'; // Send notification to Teachers? Instance depending.
$contact = core_user::get_support_user(); if ($instance->customint3 == 1) {
$info = $userWithManagerRole; $context = context_course::instance($instance->courseid);
$info->coursename = $course->fullname; $editingteacherroles = get_archetype_roles('editingteacher');
email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body); $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 getRelatedInfo($enrolid){ // Send notification to managers in system context?
global $DB; if (get_config('enrol_apply', 'sendmailtomanager') == 1) {
global $CFG; $context = context_system::instance();
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 $managerroles = get_archetype_roles('manager');
join '.$CFG->prefix.'course as c on e.courseid=c.id where ue.id='.$enrolid); $managerrole = reset($editingteacherroles);
} $managers = get_role_users($managerrole->id, $context);
function updateMailContent($content,$replace){ $manageurl = new moodle_url('/enrol/apply/manage.php');
foreach ($replace as $key=>$val) { $body = $renderer->application_notification_mail_body(
$content = str_replace("{".$key."}",$val,$content); $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);
}
}
}
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);
} }
return $content; return $content;
}
} }

157
locallib.php

@ -1,157 +0,0 @@
<?php
/**
* *************************************************************************
* * Apply Enrol **
* *************************************************************************
* @copyright emeneo.com **
* @link emeneo.com **
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **
* *************************************************************************
* ************************************************************************
*/
/**
* Self 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
*/
defined('MOODLE_INTERNAL') || die();
require_once("$CFG->libdir/formslib.php");
class enrol_apply_enrol_form extends moodleform {
protected $instance;
/**
* Overriding this function to get unique form id for multiple self enrolments
*
* @return string form identifier
*/
protected function get_form_identifier() {
$formid = $this->_customdata->id.'_'.get_class($this);
return $formid;
}
public function definition() {
global $DB;
$mform = $this->_form;
$instance = $this->_customdata;
$this->instance = $instance;
$plugin = enrol_get_plugin('apply');
$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', '<p>'.$instance->customtext1.'</p>');
$mform->addElement('textarea', 'applydescription', get_string('comment', 'enrol_apply'),'cols="80"');
//user profile
global $USER,$CFG,$DB;
require_once($CFG->libdir.'/gdlib.php');
require_once($CFG->dirroot.'/user/edit_form.php');
require_once($CFG->dirroot.'/user/editlib.php');
require_once($CFG->dirroot.'/user/profile/lib.php');
require_once($CFG->dirroot.'/user/lib.php');
$user = $DB->get_record('user',array('id'=>$USER->id));
$editoroptions = $filemanageroptions = null;
$apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'");
$show_standard_user_profile = $show_extra_user_profile = false;
if($instance->customint1 != ''){
($instance->customint1 == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false;
}else{
($apply_setting['show_standard_user_profile']->value == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false;
}
if($instance->customint2 != ''){
($instance->customint2 == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false;
}else{
($apply_setting['show_extra_user_profile']->value == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false;
}
if($show_standard_user_profile){
useredit_shared_definition($mform, $editoroptions, $filemanageroptions,$user);
}
if($show_extra_user_profile){
profile_definition($mform, $user->id);
}
$profile_default_values = $user;
if (is_object($profile_default_values)) {
$profile_default_values = (array)$profile_default_values;
}
$mform->setDefaults($profile_default_values);
$this->add_action_buttons(false, get_string('enrolme', 'enrol_self'));
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->setDefault('id', $instance->courseid);
$mform->addElement('hidden', 'instance');
$mform->setType('instance', PARAM_INT);
$mform->setDefault('instance', $instance->id);
//$mform->addElement('html',"<script type='text/javascript' src='../../lib/jquery/jquery-1.10.2.min.js'></script>");
//$mform->addElement('html','<script>$(document).ready(function(){$(".collapsible-actions a").trigger("click");})</script>');
//$mform->addElement('html','<script type="text/javascript">$(document).ready(function(){setTimeout(function(){$(".collapseexpand").trigger("click");},3000)})</script>');
}
public function validation($data, $files) {
global $DB, $CFG;
$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;
}
}

118
manage.php

@ -1,62 +1,76 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* ************************************************************************* * @package enrol_apply
* * Apply Enrol ** * @copyright emeneo.com (http://emeneo.com/)
* ************************************************************************* * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright emeneo.com ** * @author emeneo.com (http://emeneo.com/)
* @link emeneo.com ** * @author Johannes Burk <johannes.burk@sudile.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** */
* *************************************************************************
* ************************************************************************ require_once('../../config.php');
*/ require_once($CFG->dirroot.'/enrol/apply/lib.php');
require ('../../config.php'); require_once($CFG->dirroot.'/enrol/apply/manage_table.php');
require_once ('lib.php'); require_once($CFG->dirroot.'/enrol/apply/renderer.php');
$id = optional_param('id', null, PARAM_INT);
$userenrolments = optional_param_array('userenrolments', null, PARAM_INT);
require_login(); require_login();
require_capability('enrol/apply:manage', context_system::instance());
$site = get_site (); $manageurlparams = array();
$systemcontext = context_system::instance(); if ($id == null) {
$context = context_system::instance();
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('enrol/apply:manageapplications', $context);
$manageurlparams['id'] = $instance->id;
$pageheading = $course->fullname;
}
$PAGE->set_url ( '/enrol/manage.php'); $manageurl = new moodle_url('/enrol/apply/manage.php', $manageurlparams);
$PAGE->set_context($systemcontext);
$PAGE->set_pagelayout ( 'admin' );
//$PAGE->set_heading ( $course->fullname );
$PAGE->navbar->add ( get_string ( 'confirmusers', 'enrol_apply' ) ); $PAGE->set_context($context);
$PAGE->set_title ( "$site->shortname: " . get_string ( 'confirmusers', 'enrol_apply' ) ); $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'));
$PAGE->requires->css('/enrol/apply/style.css');
if (isset ( $_POST ['enrolid'] )) { if ($userenrolments != null) {
if ($_POST ['enrolid']) { $enrolapply = enrol_get_plugin('apply');
if ($_POST ['type'] == 'confirm') { if (optional_param('confirm', false, PARAM_BOOL)) {
confirmEnrolment ( $_POST ['enrolid'] ); $enrolapply->confirm_enrolment($userenrolments);
} elseif ($_POST ['type'] == 'cancel') { } else if (optional_param('wait', false, PARAM_BOOL)) {
cancelEnrolment ( $_POST ['enrolid'] ); $enrolapply->wait_enrolment($userenrolments);
} } else if (optional_param('cancel', false, PARAM_BOOL)) {
redirect ( "$CFG->wwwroot/enrol/apply/manage.php" ); $enrolapply->cancel_enrolment($userenrolments);
} }
redirect($manageurl);
} }
$enrols = getAllEnrolment(); $table = new enrol_apply_manage_table($id);
echo $OUTPUT->header (); $table->define_baseurl($manageurl);
echo $OUTPUT->heading ( get_string ( 'confirmusers', 'enrol_apply' ) );
echo '<form id="frmenrol" method="post" action="manage.php">'; $renderer = $PAGE->get_renderer('enrol_apply');
echo '<input type="hidden" id="type" name="type" value="confirm">'; $renderer->manage_page($table, $manageurl);
echo '<table class="generalbox editcourse boxaligncenter"><tr class="header">';
echo '<th class="header" scope="col">&nbsp;</th>';
echo '<th class="header" scope="col">' . get_string ( 'coursename', 'enrol_apply' ) . '</th>';
echo '<th class="header" scope="col">' . get_string ( 'applyuser', 'enrol_apply' ) . '</th>';
echo '<th class="header" scope="col">' . get_string ( 'applyusermail', 'enrol_apply' ) . '</th>';
echo '<th class="header" scope="col">' . get_string ( 'applydate', 'enrol_apply' ) . '</th>';
echo '</tr>';
foreach ( $enrols as $enrol ) {
echo '<tr><td><input type="checkbox" name="enrolid[]" value="' . $enrol->id . '"></td>';
echo '<td>' . format_string($enrol->course) . '</td>';
echo '<td>' . $enrol->firstname . ' ' . $enrol->lastname . '</td>';
echo '<td>' . $enrol->email . '</td>';
echo '<td>' . date ( "Y-m-d", $enrol->timecreated ) . '</td></tr>';
}
echo '</table>';
echo '<p align="center"><input type="button" value="' . get_string ( 'btnconfirm', 'enrol_apply' ) . '" onclick="doSubmit(\'confrim\');">&nbsp;&nbsp;<input type="button" value="' . get_string ( 'btncancel', 'enrol_apply' ) . '" onclick="doSubmit(\'cancel\');"></p>';
echo '</form>';
echo '<script>function doSubmit(type){if(type=="cancel"){document.getElementById("type").value=type;}document.getElementById("frmenrol").submit();}</script>';
echo $OUTPUT->footer ();

87
manage_table.php

@ -0,0 +1,87 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
*
* @package enrol_apply
* @copyright 2016 sudile GbR (http://www.sudile.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Johannes Burk <johannes.burk@sudile.com>
*/
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 .= " AND 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} 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);
}
/**
* 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.
*/
public 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) {
// The $row variable 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);
}
}

137
renderer.php

@ -0,0 +1,137 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
*
* @package enrol_apply
* @copyright 2016 sudile GbR (http://www.sudile.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Johannes Burk <johannes.burk@sudile.com>
*/
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 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()));
$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::end_tag('p');
echo html_writer::end_tag('form');
}
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);
}
public function application_notification_mail_body(
$course, $user, $manageurl, $applydescription, $standarduserfields = null, $extrauserfields = null) {
$body = '<p>'. get_string('coursename', 'enrol_apply') .': '.format_string($course->fullname).'</p>';
$body .= '<p>'. get_string('applyuser', 'enrol_apply') .': '.$user->firstname.' '.$user->lastname.'</p>';
$body .= '<p>'. get_string('comment', 'enrol_apply') .': '.$applydescription.'</p>';
if ($standarduserfields) {
$body .= '<p><strong>'. get_string('user_profile', 'enrol_apply').'</strong></p>';
$body .= '<p>'. get_string('firstname') .': '.$standarduserfields->firstname.'</p>';
$body .= '<p>'. get_string('lastname') .': '.$standarduserfields->lastname.'</p>';
$body .= '<p>'. get_string('email') .': '.$standarduserfields->email.'</p>';
$body .= '<p>'. get_string('city') .': '.$standarduserfields->city.'</p>';
$body .= '<p>'. get_string('country') .': '.$standarduserfields->country.'</p>';
$body .= '<p>'. get_string('preferredlanguage') .': '.$standarduserfields->lang.'</p>';
$body .= '<p>'. get_string('description') .': '.$standarduserfields->description_editor['text'].'</p>';
$body .= '<p>'. get_string('firstnamephonetic') .': '.$standarduserfields->firstnamephonetic.'</p>';
$body .= '<p>'. get_string('lastnamephonetic') .': '.$standarduserfields->lastnamephonetic.'</p>';
$body .= '<p>'. get_string('middlename') .': '.$standarduserfields->middlename.'</p>';
$body .= '<p>'. get_string('alternatename') .': '.$standarduserfields->alternatename.'</p>';
$body .= '<p>'. get_string('url') .': '.$standarduserfields->url.'</p>';
$body .= '<p>'. get_string('icqnumber') .': '.$standarduserfields->icq.'</p>';
$body .= '<p>'. get_string('skypeid') .': '.$standarduserfields->skype.'</p>';
$body .= '<p>'. get_string('aimid') .': '.$standarduserfields->aim.'</p>';
$body .= '<p>'. get_string('yahooid') .': '.$standarduserfields->yahoo.'</p>';
$body .= '<p>'. get_string('msnid') .': '.$standarduserfields->msn.'</p>';
$body .= '<p>'. get_string('idnumber') .': '.$standarduserfields->idnumber.'</p>';
$body .= '<p>'. get_string('institution') .': '.$standarduserfields->institution.'</p>';
$body .= '<p>'. get_string('department') .': '.$standarduserfields->department.'</p>';
$body .= '<p>'. get_string('phone') .': '.$standarduserfields->phone1.'</p>';
$body .= '<p>'. get_string('phone2') .': '.$standarduserfields->phone2.'</p>';
$body .= '<p>'. get_string('address') .': '.$standarduserfields->address.'</p>';
}
if ($extrauserfields) {
foreach ($extrauserfields as $key => $value) {
$body .= '<p>'. $key .': '.$value.'</p>';
}
}
$body .= '<p>'. html_writer::link($manageurl, get_string('applymanage', 'enrol_apply')).'</p>';
return $body;
}
}

155
selectlib.php

@ -1,155 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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 <type> $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 <type> $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/locallib.php';
return $options;
}
}

143
settings.php

@ -1,40 +1,107 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* ************************************************************************* * @package enrol_apply
* * Apply Enrol ** * @copyright emeneo.com (http://emeneo.com/)
* ************************************************************************* * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright emeneo.com ** * @author emeneo.com (http://emeneo.com/)
* @link emeneo.com ** * @author Johannes Burk <johannes.burk@sudile.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** */
* *************************************************************************
* ************************************************************************
*/
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
if ($ADMIN->fulltree) { 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_heading('enrol_apply_enrolname','',get_string('pluginname_desc', 'enrol_apply')));
// Confirm mail settings...
$settings->add(new admin_setting_configtext('enrol_apply/confirmmailsubject','',get_string('confirmmailsubject', 'enrol_apply'),null,PARAM_TEXT,60)); $settings->add(new admin_setting_heading(
'enrol_apply_confirmmail',
$settings->add(new admin_setting_heading('enrol_apply_confirmmailcontent', '', get_string('confirmmailcontent_desc', 'enrol_apply'))); get_string('confirmmail_heading', 'enrol_apply'),
$settings->add(new admin_setting_confightmleditor('enrol_apply/confirmmailcontent', get_string('confirmmailcontent', 'enrol_apply'),'utf-8','')); get_string('confirmmail_desc', 'enrol_apply')));
$settings->add(new admin_setting_configtext(
$settings->add(new admin_setting_configtext('enrol_apply/waitmailsubject','',get_string('waitmailsubject', 'enrol_apply'),null,PARAM_TEXT,60)); 'enrol_apply/confirmmailsubject',
get_string('confirmmailsubject', 'enrol_apply'),
$settings->add(new admin_setting_heading('enrol_apply_waitmailcontent', '', get_string('waitmailcontent_desc', 'enrol_apply'))); get_string('confirmmailsubject_desc', 'enrol_apply'),
$settings->add(new admin_setting_confightmleditor('enrol_apply/waitmailcontent', get_string('waitmailcontent', 'enrol_apply'),'utf-8','')); null,
PARAM_TEXT,
$settings->add(new admin_setting_configtext('enrol_apply/cancelmailsubject','',get_string('cancelmailsubject', 'enrol_apply'),null,PARAM_TEXT,60)); 60));
$settings->add(new admin_setting_confightmleditor(
$settings->add(new admin_setting_heading('enrol_apply_cancelmailcontent', '', get_string('cancelmailcontent_desc', 'enrol_apply'))); 'enrol_apply/confirmmailcontent',
$settings->add(new admin_setting_confightmleditor('enrol_apply/cancelmailcontent', get_string('cancelmailcontent', 'enrol_apply'),'utf-8','')); get_string('confirmmailcontent', 'enrol_apply'),
get_string('confirmmailcontent_desc', 'enrol_apply'),
$settings->add(new admin_setting_configcheckbox('enrol_apply/sendmailtoteacher', get_string('sendmailtoteacher', 'enrol_apply'), '', 0)); null,
$settings->add(new admin_setting_configcheckbox('enrol_apply/sendmailtomanager', get_string('sendmailtomanager', 'enrol_apply'), '', 0)); PARAM_RAW));
//--- enrol instance defaults ---------------------------------------------------------------------------- // 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_RAW));
// 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_RAW));
// 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));
// Enrol instance defaults...
$settings->add(new admin_setting_heading('enrol_manual_defaults', $settings->add(new admin_setting_heading('enrol_manual_defaults',
get_string('enrolinstancedefaults', 'admin'), get_string('enrolinstancedefaults_desc', 'admin'))); get_string('enrolinstancedefaults', 'admin'), get_string('enrolinstancedefaults_desc', 'admin')));
@ -46,15 +113,15 @@ if ($ADMIN->fulltree) {
$settings->add(new admin_setting_configselect('enrol_apply/status', $settings->add(new admin_setting_configselect('enrol_apply/status',
get_string('status', 'enrol_apply'), get_string('status_desc', 'enrol_apply'), ENROL_INSTANCE_ENABLED, $options)); get_string('status', 'enrol_apply'), get_string('status_desc', 'enrol_apply'), ENROL_INSTANCE_ENABLED, $options));
$options = array(ENROL_INSTANCE_ENABLED => get_string('yes'), $options = array(1 => get_string('yes'),
ENROL_INSTANCE_DISABLED => get_string('no')); 0 => get_string('no'));
$settings->add(new admin_setting_configselect('enrol_apply/show_standard_user_profile', $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'), $options = array(1 => get_string('yes'),
ENROL_INSTANCE_DISABLED => get_string('no')); 0 => get_string('no'));
$settings->add(new admin_setting_configselect('enrol_apply/show_extra_user_profile', $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()) { if (!during_initial_install()) {
$options = get_default_enrol_roles(context_system::instance()); $options = get_default_enrol_roles(context_system::instance());
@ -65,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', $ADMIN->add('courses', new admin_externalpage('enrol_apply',
get_string('applymanage', 'enrol_apply'), get_string('applymanage', 'enrol_apply'),
new moodle_url('/enrol/apply/manage.php'))); new moodle_url('/enrol/apply/manage.php')));

3
style.css

@ -0,0 +1,3 @@
.enrol_apply_waitinglist_highlight {
border-left: 6px solid grey;
}

27
unenrolself.php

@ -15,9 +15,12 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* 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} * @copyright 2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
@ -27,8 +30,8 @@ require('../../config.php');
$enrolid = required_param('enrolid', PARAM_INT); $enrolid = required_param('enrolid', PARAM_INT);
$confirm = optional_param('confirm', 0, PARAM_BOOL); $confirm = optional_param('confirm', 0, PARAM_BOOL);
$instance = $DB->get_record('enrol', array('id'=>$enrolid, 'enrol'=>'apply'), '*', 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); $course = $DB->get_record('course', array('id' => $instance->courseid), '*', MUST_EXIST);
$context = context_course::instance($course->id, MUST_EXIST); $context = context_course::instance($course->id, MUST_EXIST);
require_login(); require_login();
@ -41,26 +44,22 @@ $plugin = enrol_get_plugin('apply');
// Security defined inside following function. // Security defined inside following function.
if (!$plugin->get_unenrolself_link($instance)) { 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)); $PAGE->set_title($plugin->get_instance_name($instance));
if ($confirm and confirm_sesskey()) { if ($confirm and confirm_sesskey()) {
$plugin->unenrol_user($instance, $USER->id); $plugin->unenrol_user($instance, $USER->id);
// Deprecated fixed by Shiro <gigashiro@gmail.com>
//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')); redirect(new moodle_url('/index.php'));
} }
echo $OUTPUT->header(); echo $OUTPUT->header();
$yesurl = new moodle_url($PAGE->url, array('confirm'=>1, 'sesskey'=>sesskey())); $yesurl = new moodle_url($PAGE->url, array('confirm' => 1, 'sesskey' => sesskey()));
$nourl = new moodle_url('/course/view.php', array('id'=>$course->id)); $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 // 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->confirm($message, $yesurl, $nourl);
echo $OUTPUT->footer(); echo $OUTPUT->footer();

98
unenroluser.php

@ -1,98 +0,0 @@
<?php
/**
* *************************************************************************
* * Apply Enrol **
* *************************************************************************
* @copyright emeneo.com **
* @link emeneo.com **
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **
* *************************************************************************
* ************************************************************************
*/
/**
* Unenrol a user who was enrolled through a self enrolment.
*
* @package enrol
* @subpackage self
* @copyright 2011 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
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
$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();

36
version.php

@ -1,24 +1,30 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* ************************************************************************* * @package enrol_apply
* * Apply Enrol ** * @copyright emeneo.com (http://emeneo.com/)
* *************************************************************************
* @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/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author emeneo.com (http://emeneo.com/)
* @author Johannes Burk <johannes.burk@sudile.com>
*/ */
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->version = 2016042201; $plugin->version = 2016042203;
$plugin->requires = 2011080100; $plugin->requires = 2011080100;
$plugin->maturity = MATURITY_STABLE; $plugin->maturity = MATURITY_STABLE;
$plugin->release = 'Enrolment upon approval plugin Version 3.0-d'; $plugin->release = 'Enrolment upon approval plugin Version 3.0-d';

Loading…
Cancel
Save