From 165088f6874a845653d1a5610ec6bdccb2b5b45c Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Tue, 2 Oct 2007 03:37:30 +0000 Subject: [PATCH] change participants of frontpage course to display all users, if current user has capability MDL-11143 --- blocks/participants/block_participants.php | 27 ++++--- lib/db/access.php | 9 +++ user/index.php | 88 +++++++++++++++------- user/tabs.php | 2 +- version.php | 2 +- 5 files changed, 89 insertions(+), 39 deletions(-) diff --git a/blocks/participants/block_participants.php b/blocks/participants/block_participants.php index 16670424d4..f6ecc93e76 100644 --- a/blocks/participants/block_participants.php +++ b/blocks/participants/block_participants.php @@ -19,22 +19,29 @@ class block_participants extends block_list { if (empty($this->instance->pageid)) { return ''; } - + + $this->content = new object(); + $this->content->items = array(); + $this->content->icons = array(); + $this->content->footer = ''; + if (!$currentcontext = get_context_instance(CONTEXT_COURSE, $this->instance->pageid)) { $this->content = ''; return $this->content; } - - if (!has_capability('moodle/course:viewparticipants', $currentcontext)) { - $this->content = ''; - return $this->content; + + if ($this->instance->pageid == SITEID) { + if (!has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) { + $this->content = ''; + return $this->content; + } + } else { + if (!has_capability('moodle/course:viewparticipants', $currentcontext)) { + $this->content = ''; + return $this->content; + } } - $this->content = new object(); - $this->content->items = array(); - $this->content->icons = array(); - $this->content->footer = ''; - $this->content->items[] = ''.get_string('participants').''; $this->content->icons[] = ''; diff --git a/lib/db/access.php b/lib/db/access.php index 77d13f7b3c..870d2e82de 100644 --- a/lib/db/access.php +++ b/lib/db/access.php @@ -597,6 +597,15 @@ $moodle_capabilities = array( 'admin' => CAP_ALLOW ) ), + + 'moodle/site:viewparticipants' => array( + + 'captype' => 'read', + 'contextlevel' => CONTEXT_SYSTEM, + 'legacy' => array( + 'admin' => CAP_ALLOW + ) + ), 'moodle/course:viewscales' => array( diff --git a/user/index.php b/user/index.php index be147f3d77..f76090231d 100644 --- a/user/index.php +++ b/user/index.php @@ -42,11 +42,19 @@ require_login($course); $sitecontext = get_context_instance(CONTEXT_SYSTEM); + $frontpagectx = get_context_instance(CONTEXT_COURSE, SITEID); - if (!has_capability('moodle/course:viewparticipants', $context)) { - print_error('nopermissions'); + if ($context->id != $frontpagectx->id) { + if (!has_capability('moodle/course:viewparticipants', $context)) { + print_error('nopermissions'); + } + } else { + if (!has_capability('moodle/site:viewparticipants', $sitecontext)) { + print_error('nopermissions'); + } } + /// front page course is different $rolenames = array(); $avoidroles = array(); @@ -74,8 +82,9 @@ } } - // no roles to display yet? - if (empty($rolenames)) { + // no roles to display yet? + // frontpage course is an exception, on the front page course we should display all users + if (empty($rolenames) && $context->id != $frontpagectx->id) { if (has_capability('moodle/role:assign', $context)) { redirect($CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id); } else { @@ -259,7 +268,6 @@ } } - /// Define a table showing a list of users in the current role selection $tablecolumns = array('userpic', 'fullname'); @@ -321,24 +329,41 @@ } else { $selectrole = " "; } - $select = 'SELECT u.id, u.username, u.firstname, u.lastname, + + if ($context->id != $frontpagectx->id) { + $select = 'SELECT u.id, u.username, u.firstname, u.lastname, u.email, u.city, u.country, u.picture, u.lang, u.timezone, u.emailstop, u.maildisplay, u.imagealt, COALESCE(ul.timeaccess, 0) AS lastaccess, r.hidden, ctx.id AS ctxid, ctx.path AS ctxpath, + ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel '; + $select .= $course->enrolperiod?', r.timeend ':''; + } else { + $select = 'SELECT u.id, u.username, u.firstname, u.lastname, + u.email, u.city, u.country, u.picture, + u.lang, u.timezone, u.emailstop, u.maildisplay, u.imagealt, + u.lastaccess, + ctx.id AS ctxid, ctx.path AS ctxpath, ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel '; + + } - $select .= $course->enrolperiod?', r.timeend ':''; - - $from = "FROM {$CFG->prefix}user u - LEFT OUTER JOIN {$CFG->prefix}context ctx - ON (u.id=ctx.instanceid AND ctx.contextlevel = ".CONTEXT_USER.") - JOIN {$CFG->prefix}role_assignments r - ON u.id=r.userid - LEFT OUTER JOIN {$CFG->prefix}user_lastaccess ul - ON (r.userid=ul.userid and ul.courseid = $course->id) "; - + if ($context->id != $frontpagectx->id) { + $from = "FROM {$CFG->prefix}user u + LEFT OUTER JOIN {$CFG->prefix}context ctx + ON (u.id=ctx.instanceid AND ctx.contextlevel = ".CONTEXT_USER.") + JOIN {$CFG->prefix}role_assignments r + ON u.id=r.userid + LEFT OUTER JOIN {$CFG->prefix}user_lastaccess ul + ON (r.userid=ul.userid and ul.courseid = $course->id) "; + } else { + $from = "FROM {$CFG->prefix}user u + LEFT OUTER JOIN {$CFG->prefix}context ctx + ON (u.id=ctx.instanceid AND ctx.contextlevel = ".CONTEXT_USER.") "; + + } + $hiddensql = has_capability('moodle/role:viewhiddenassigns', $context)? '':' AND r.hidden = 0 '; // exclude users with roles we are avoiding @@ -353,14 +378,20 @@ // join on 2 conditions // otherwise we run into the problem of having records in ul table, but not relevant course // and user record is not pulled out - $where = "WHERE (r.contextid = $context->id OR r.contextid in $listofcontexts) - AND u.deleted = 0 $selectrole - AND (ul.courseid = $course->id OR ul.courseid IS NULL) - AND u.username != 'guest' - $adminroles - $hiddensql "; - $where .= get_lastaccess_sql($accesssince); - + + if ($context->id != $frontpagectx->id) { + $where = "WHERE (r.contextid = $context->id OR r.contextid in $listofcontexts) + AND u.deleted = 0 $selectrole + AND (ul.courseid = $course->id OR ul.courseid IS NULL) + AND u.username != 'guest' + $adminroles + $hiddensql "; + $where .= get_lastaccess_sql($accesssince); + } else { + $where = "WHERE u.deleted = 0 + AND u.username != 'guest'"; + $where .= get_lastaccess_sql($accesssince); + } $wheresearch = ''; if (!empty($search)) { @@ -611,12 +642,15 @@ if (has_capability('moodle/site:readallmessages', $context) && !empty($CFG->messaging)) { $displaylist['messageselect.php'] = get_string('messageselectadd'); } - if (has_capability('moodle/notes:manage', $context)) { + if (has_capability('moodle/notes:manage', $context) && $context->id != $frontpagectx->id) { $displaylist['addnote.php'] = get_string('addnewnote', 'notes'); $displaylist['groupaddnote.php'] = get_string('groupaddnewnote', 'notes'); } - $displaylist['extendenrol.php'] = get_string('extendenrol'); - $displaylist['groupextendenrol.php'] = get_string('groupextendenrol'); + + if ($context->id != $frontpagectx->id) { + $displaylist['extendenrol.php'] = get_string('extendenrol'); + $displaylist['groupextendenrol.php'] = get_string('groupextendenrol'); + } helpbutton("participantswithselectedusers", get_string("withselectedusers")); choose_from_menu ($displaylist, "formaction", "", get_string("withselectedusers"), "if(checksubmit(this.form))this.form.submit();", ""); diff --git a/user/tabs.php b/user/tabs.php index 4990e58297..1822b19e3c 100644 --- a/user/tabs.php +++ b/user/tabs.php @@ -34,7 +34,7 @@ print_heading(format_string($site->fullname)); if ($CFG->bloglevel >= 4) { - if (has_capability('moodle/course:viewparticipants', get_context_instance(CONTEXT_SYSTEM, SITEID))) { + if (has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) { $toprow[] = new tabobject('participants', $CFG->wwwroot.'/user/index.php?id='.SITEID, get_string('participants')); } diff --git a/version.php b/version.php index 4452f3f579..9fda03bfe7 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2007092806; // YYYYMMDD = date + $version = 2007092807; // YYYYMMDD = date // XY = increments within a single day $release = '1.9 Beta +'; // Human-friendly version name -- 2.39.5