Permalink
Browse files

mnet: fixup remote enrolment handling pages - WIP part 2

  • Loading branch information...
1 parent 0d061d8 commit efd6ef46659b9d4641a8058553c33b246c48e583 martinlanghoff committed Jan 19, 2007
Showing with 61 additions and 41 deletions.
  1. +6 −10 admin/mnet/enr_course_enrol.html
  2. +55 −31 admin/mnet/enr_course_enrol.php
@@ -21,11 +21,9 @@
getElementById('assignform').remove.disabled=false;
getElementById('assignform').addselect.selectedIndex=-1;">
<?php
- foreach ($enrolledusers as $enrolleduser) {
- if ($enrolleduser->enroltype == 'mnet') {
- $fullname = fullname($enrolleduser, true);
- echo "<option value=\"$enrolleduser->id\">".$fullname.", ".$enrolleduser->email."</option>\n";
- }
+ foreach ($mnetenrolledusers as $enrolleduser) {
+ $fullname = fullname($enrolleduser, true);
+ echo "<option value=\"$enrolleduser->id\">".s($fullname)." (".s($enrolleduser->rolename).")</option>\n";
}
?>
@@ -93,11 +91,9 @@
<tr>
<td valign="top"><?php print_string('otherenrolledusers', 'mnet'); ?>:<br />
<?php
- foreach ($enrolledusers as $enrolleduser) {
- if ($enrolleduser->enroltype != 'mnet') {
- $fullname = fullname($enrolleduser, true);
- echo $fullname.', '.$enrolleduser->email."<br />\n";
- }
+ foreach ($remtenrolledusers as $enrolleduser) {
+ $fullname = fullname($enrolleduser, true);
+ echo s($fullname) .', ('.s($enrolleduser->rolename) . ') '.s($enrolleduser->enroltype)."<br />\n";
}
?></td>
<td valign="top"></td>
@@ -151,14 +151,18 @@
delete_record('mnet_enrol_assignments', 'id', $user->enrolid);
}
}
+ unset($enrolledusers);
-
+ // Read about our remote enrolments in 2 sets
+ // first, get the remote enrolments done via enrol/mnet $mnetenrolledusers
+ // second, get the remote enrolments done with other plugins $remtenrolledusers
+ // NOTE: both arrays are keyed on the userid!
$sql = "
SELECT
u.id,
u.firstname,
u.lastname,
- u.email,
+ a.rolename,
a.enroltype,
a.courseid
FROM
@@ -167,25 +171,50 @@
WHERE
a.userid = u.id AND
a.courseid={$courseid} AND
+ a.enroltype = 'mnet' AND
u.deleted = 0 AND
u.confirmed = 1 AND
u.mnethostid = {$CFG->mnet_localhost_id}
ORDER BY
u.firstname ASC,
u.lastname ASC";
- if (!$enrolledusers = get_records_sql($sql)) {
- $enrolledusers = array();
+ if (!$mnetenrolledusers = get_records_sql($sql)) {
+ $mnetenrolledusers = array();
}
+ $sql = "
+ SELECT
+ u.id,
+ u.firstname,
+ u.lastname,
+ a.rolename,
+ a.enroltype,
+ a.courseid
+ FROM
+ {$CFG->prefix}user u,
+ {$CFG->prefix}mnet_enrol_assignments a
+ WHERE
+ a.userid = u.id AND
+ a.courseid={$courseid} AND
+ a.enroltype != 'mnet' AND
+ u.deleted = 0 AND
+ u.confirmed = 1 AND
+ u.mnethostid = {$CFG->mnet_localhost_id}
+ ORDER BY
+ u.firstname ASC,
+ u.lastname ASC";
- $excludeids = ' ';
- foreach($enrolledusers as $user) {
- $excludeids .= "$user->id, ";
+ if (!$remtenrolledusers = get_records_sql($sql)) {
+ $remtenrolledusers = array();
}
- $select = 'AND u.id NOT IN ( 0, ' .substr($excludeids, 0, -2) .') ';
- $searchtext = trim($searchtext);
$select = '';
+ $exclude = array_merge(array_keys($mnetenrolledusers), array_keys($remtenrolledusers));
+ $exclude[] = 0;
+ $select = 'AND u.username!=\'guest\' AND u.id NOT IN ('. join(',',$exclude) .') ';
+ unset($exclude);
+
+ $searchtext = trim($searchtext);
if ($searchtext !== '') { // Search for a subset of remaining users
$LIKE = sql_ilike();
@@ -194,10 +223,14 @@
$select .= " AND ($FULLNAME $LIKE '%$searchtext%' OR email $LIKE '%$searchtext%') ";
}
- $availableusers = get_recordset_sql('SELECT id, firstname, lastname, email
- FROM '.$CFG->prefix.'user
- WHERE deleted = 0 AND confirmed = 1 AND mnethostid = '.$CFG->mnet_localhost_id.' '.$select.'
- ORDER BY lastname ASC, firstname ASC', 0, MAX_USERS_PER_PAGE);
+ $sql = ('SELECT id, firstname, lastname, email
+ FROM '.$CFG->prefix.'user u
+ WHERE deleted = 0 AND confirmed = 1
+ AND mnethostid = '.$CFG->mnet_localhost_id.' '
+ .$select
+ .'ORDER BY lastname ASC, firstname ASC');
+
+ $availableusers = get_recordset_sql($sql, 0, MAX_USERS_PER_PAGE);
@@ -220,32 +253,23 @@
admin_externalpage_print_header($adminroot);
-print_simple_box_start("center", "80%");
-
-print_simple_box_start("center", "60%", '', 5, 'informationbox');
print_string('enrollingincourse', 'mnet', array(s($course->shortname), s($mnet_peer->name)));
print_string("description", "enrol_mnet");
-print_simple_box_end();
echo "<hr />";
- print_simple_box_start('center');
- include(dirname(__FILE__).'/enr_course_enrol.html');
- print_simple_box_end();
+include(dirname(__FILE__).'/enr_course_enrol.html');
- if (!empty($errors)) {
- $msg = '<p>';
- foreach ($errors as $e) {
- $msg .= $e.'<br />';
- }
- $msg .= '</p>';
- print_simple_box_start('center');
- notify($msg);
- print_simple_box_end();
- }
+if (!empty($errors)) {
+ $msg = '<p>';
+ foreach ($errors as $e) {
+ $msg .= $e.'<br />';
+ }
+ $msg .= '</p>';
+ notify($msg);
+}
-print_simple_box_end();
admin_externalpage_print_footer($adminroot);
?>

0 comments on commit efd6ef4

Please sign in to comment.