Browse Source

Refactor: combine manage.php and apply.php to manage.php,

rename locallib.php to apply_form.php and containing class
from enrol_apply_enrol_form to enrol_apply_apply_form
refactor code in manage.php
SABERES_37_STABLE
Johannes Burk 9 years ago
committed by test
parent
commit
9bf08acb8e
  1. 112
      apply.php
  2. 2
      apply_form.php
  3. 32
      lib.php
  4. 128
      manage.php
  5. 2
      selectlib.php
  6. 1
      unenroluser.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);
}

2
locallib.php → apply_form.php

@ -23,7 +23,7 @@ defined('MOODLE_INTERNAL') || die();
require_once("$CFG->libdir/formslib.php"); require_once("$CFG->libdir/formslib.php");
class enrol_apply_enrol_form extends moodleform { class enrol_apply_apply_form extends moodleform {
protected $instance; protected $instance;
/** /**

32
lib.php

@ -22,17 +22,22 @@ 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));
} }
@ -44,18 +49,16 @@ class enrol_apply_plugin extends enrol_plugin {
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()) {
// Only process when form submission is for this instance (multi instance support).
if ($data->instance == $instance->id) {
$userInfo = $data; $userInfo = $data;
$applydescription = $userInfo->applydescription; $applydescription = $userInfo->applydescription;
unset($userInfo->applydescription); unset($userInfo->applydescription);
@ -124,13 +127,10 @@ class enrol_apply_plugin extends enrol_plugin {
redirect("$CFG->wwwroot/course/view.php?id=$instance->courseid"); 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) {
@ -149,7 +149,7 @@ class enrol_apply_plugin extends enrol_plugin {
} }
if (has_capability('enrol/apply:manage', $context)) { if (has_capability('enrol/apply:manage', $context)) {
$managelink = new moodle_url("/enrol/apply/apply.php", array('id'=>$_GET['id'],'enrolid'=>$instance->id)); $managelink = new moodle_url("/enrol/apply/manage.php", array('id'=>$instance->id));
$icons[] = $OUTPUT->action_icon($managelink, new pix_icon('i/users', get_string('confirmenrol', 'enrol_apply'), 'core', array('class'=>'iconsmall'))); $icons[] = $OUTPUT->action_icon($managelink, new pix_icon('i/users', get_string('confirmenrol', 'enrol_apply'), 'core', array('class'=>'iconsmall')));
} }
@ -253,7 +253,7 @@ function getAllEnrolment($id = null) {
AND e.id = ?'; AND e.id = ?';
$userenrolments = $DB->get_records_sql($sql, array($id)); $userenrolments = $DB->get_records_sql($sql, array($id));
} else { } else {
$sql = 'SELECT ue.id,ue.userid,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated $sql = 'SELECT ue.id,ue.userid,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated,ue.status
FROM {user_enrolments} ue FROM {user_enrolments} ue
LEFT JOIN {user} u LEFT JOIN {user} u
ON ue.userid = u.id ON ue.userid = u.id
@ -425,7 +425,7 @@ function sendConfirmMailToTeachers($instance,$info,$applydescription){
} }
} }
$body .= '<p>'. html_writer::link(new moodle_url("/enrol/apply/apply.php", array('id'=>$courseid,'enrolid'=>$instanceid)), get_string('applymanage', 'enrol_apply')).'</p>'; $body .= '<p>'. html_writer::link(new moodle_url("/enrol/apply/manage.php", array('id'=>$instanceid)), get_string('applymanage', 'enrol_apply')).'</p>';
$contact = core_user::get_support_user(); $contact = core_user::get_support_user();
$info = $editTeacher; $info = $editTeacher;
$info->coursename = $course->fullname; $info->coursename = $course->fullname;

128
manage.php

@ -9,54 +9,130 @@
* ************************************************************************* * *************************************************************************
* ************************************************************************ * ************************************************************************
*/ */
require ('../../config.php');
require_once ('lib.php'); require_once ('../../config.php');
require_once($CFG->dirroot.'/enrol/apply/lib.php');
$id = optional_param('id', null, PARAM_INT);
$userenrolments = optional_param_array('userenrolments', null, PARAM_INT);
require_login(); require_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:manage', $context);
$pageheading = get_string('confirmusers', 'enrol_apply');
} else {
$instance = $DB->get_record('enrol', array('id'=>$id, 'enrol'=>'apply'), '*', MUST_EXIST);
require_course_login($instance->courseid);
$course = get_course($instance->courseid);
$context = context_course::instance($course->id, MUST_EXIST);
require_capability('moodle/course:enrolreview', $context);
$manageurlparams['id'] = $instance->id;
$pageheading = $course->fullname;
}
$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'));
if (isset ( $_POST ['enrolid'] )) { if ($userenrolments != null) {
if ($_POST ['enrolid']) { $action = required_param('type', PARAM_TEXT);
if ($_POST ['type'] == 'confirm') { switch ($action) {
confirmEnrolment ( $_POST ['enrolid'] ); case 'confirm':
} elseif ($_POST ['type'] == 'cancel') { confirmEnrolment($userenrolments);
cancelEnrolment ( $_POST ['enrolid'] ); break;
} case 'wait':
redirect ( "$CFG->wwwroot/enrol/apply/manage.php" ); waitEnrolment ($userenrolments);
break;
case 'cancel':
cancelEnrolment($userenrolments);
break;
default:
# code...
break;
} }
redirect($manageurl);
}
$enrols = getAllEnrolment($id);
if ($id == null) {
$applicationinfo = $DB->get_records_sql('
SELECT userenrolmentid, comment
FROM {enrol_apply_applicationinfo}
WHERE userenrolmentid IN (
SELECT id
FROM {user_enrolments}
WHERE enrolid IN (
SELECT id
FROM {enrol}
WHERE enrol = ?))', array('apply'));
} else {
$applicationinfo = $DB->get_records_sql('
SELECT userenrolmentid, comment
FROM {enrol_apply_applicationinfo}
WHERE userenrolmentid IN (
SELECT id
FROM {user_enrolments}
WHERE enrolid = ?)', array($instance->id));
} }
$enrols = getAllEnrolment();
echo $OUTPUT->header (); echo $OUTPUT->header ();
echo $OUTPUT->heading ( get_string ( 'confirmusers', 'enrol_apply' ) ); echo $OUTPUT->heading ( get_string ( 'confirmusers', 'enrol_apply' ) );
echo '<form id="frmenrol" method="post" action="manage.php">'; echo get_string('confirmusers_desc', 'enrol_apply');
echo '<form id="frmenrol" method="post" action="manage.php?id=' . $id . '">';
echo '<input type="hidden" id="type" name="type" value="confirm">'; echo '<input type="hidden" id="type" name="type" value="confirm">';
echo '<table class="generalbox editcourse boxaligncenter"><tr class="header">'; echo '<table class="generalbox editcourse boxaligncenter"><tr class="header">';
echo '<th class="header" scope="col">&nbsp;</th>'; 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 ( '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 ( 'applyuser', 'enrol_apply' ) . '</th>';
echo '<th class="header" scope="col">' . get_string ( 'applyusermail', '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 ( 'applydate', 'enrol_apply' ) . '</th>';
echo '<th class="header" scope="col">' . get_string ( 'comment', 'enrol_apply' ) . '</th>';
echo '</tr>'; echo '</tr>';
foreach ( $enrols as $enrol ) { foreach ( $enrols as $enrol ) {
echo '<tr><td><input type="checkbox" name="enrolid[]" value="' . $enrol->id . '"></td>'; $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>' . format_string($enrol->course) . '</td>';
echo '<td>' . $enrol->firstname . ' ' . $enrol->lastname . '</td>'; echo '<td>' . $OUTPUT->render($picture) . '</td>';
echo '<td>'.$enrol->firstname . ' ' . $enrol->lastname.'</td>';
echo '<td>' . $enrol->email . '</td>'; echo '<td>' . $enrol->email . '</td>';
echo '<td>' . date ( "Y-m-d", $enrol->timecreated ) . '</td></tr>'; echo '<td>' . date ( "Y-m-d", $enrol->timecreated ) . '</td>';
echo '<td>' . htmlspecialchars($applicationinfo[$enrol->id]->comment) . '</td>';
echo '</tr>';
} }
echo '</table>'; 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 '<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 '</form>';
echo '<script>function doSubmit(type){if(type=="cancel"){document.getElementById("type").value=type;}document.getElementById("frmenrol").submit();}</script>'; echo '<script>function doSubmit(type){
document.getElementById("type").value=type;
document.getElementById("frmenrol").submit();
}</script>';
echo $OUTPUT->footer (); 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);
}

2
selectlib.php

@ -149,7 +149,7 @@ class enrol_apply_current_participant extends user_selector_base {
protected function get_options() { protected function get_options() {
$options = parent::get_options(); $options = parent::get_options();
$options['enrolid'] = $this->enrolid; $options['enrolid'] = $this->enrolid;
$options['file'] = 'enrol/apply/locallib.php'; $options['file'] = 'enrol/apply/apply_form.php';
return $options; return $options;
} }
} }

1
unenroluser.php

@ -19,7 +19,6 @@
*/ */
require('../../config.php'); require('../../config.php');
require_once("$CFG->dirroot/enrol/locallib.php");
require_once("$CFG->dirroot/enrol/renderer.php"); require_once("$CFG->dirroot/enrol/renderer.php");
$ueid = required_param('ue', PARAM_INT); // user enrolment id $ueid = required_param('ue', PARAM_INT); // user enrolment id

Loading…
Cancel
Save