From 7e17f43b1c37783d514fa85985cd0d930cd8d581 Mon Sep 17 00:00:00 2001 From: moodler Date: Fri, 21 Sep 2007 04:33:50 +0000 Subject: [PATCH] Just a small change to make this function a bit more robust, there's still a bug here though --- lib/accesslib.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/accesslib.php b/lib/accesslib.php index bd4585311c..44a2299ba3 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -1383,25 +1383,30 @@ function get_user_access_bycontext($userid, $context, $accessdata=NULL) { } // We will want overrides for all of them - $roleids = implode(',',array_merge($courseroles,$localroles)); + $whereroles = ''; + if ($roleids = implode(',',array_merge($courseroles,$localroles))) { + $whereroles = "rc.roleid IN ($roleids) AND"; + } $sql = "SELECT ctx.path, rc.roleid, rc.capability, rc.permission FROM {$CFG->prefix}role_capabilities rc JOIN {$CFG->prefix}context ctx ON rc.contextid=ctx.id - WHERE (rc.roleid IN ($roleids) - AND (ctx.id={$context->id} OR ctx.path LIKE '{$context->path}/%')) + WHERE ($whereroles + (ctx.id={$context->id} OR ctx.path LIKE '{$context->path}/%')) $wherelocalroles ORDER BY ctx.depth ASC, ctx.path DESC, rc.roleid ASC "; - $rs = get_recordset_sql($sql); - - if ($rs->RecordCount()) { - while ($rd = rs_fetch_next_record($rs)) { - $k = "{$rd->path}:{$rd->roleid}"; - $accessdata['rdef'][$k][$rd->capability] = $rd->permission; + if ($rs = get_recordset_sql($sql)) { + if ($rs->RecordCount()) { + while ($rd = rs_fetch_next_record($rs)) { + $k = "{$rd->path}:{$rd->roleid}"; + $accessdata['rdef'][$k][$rd->capability] = $rd->permission; + } } + rs_close($rs); + } else { + debugging('Bad SQL encountered!'); } - rs_close($rs); // TODO: compact capsets? -- 2.39.5