echo '<form action="allowassign.php" method="post">';
print_table($table);
- echo '<div class="singlebutton"><input type="submit" value="'.get_string('savechanges').'"/></div>';
+ echo '<div class="buttons"><input type="submit" value="'.get_string('savechanges').'"/></div>';
echo '<input type="hidden" name="dummy" value="1" />'; // this is needed otherwise we do not know a form has been submitted
echo '</form>';
echo '<form action="allowoverride.php" method="post">';
print_table($table);
- echo '<div class="singlebutton"><input type="submit" value="'.get_string('savechanges').'"/></div>';
+ echo '<div class="buttons"><input type="submit" value="'.get_string('savechanges').'"/></div>';
echo '<input type="hidden" name="dummy" value="1" />'; // this is needed otherwise we do not know a form has been submitted
echo '</form>';
onfocus="getElementById('assignform').add.disabled=true;
getElementById('assignform').remove.disabled=false;
getElementById('assignform').addselect.selectedIndex=-1;">
-
+
<?php
foreach ($contextusers as $contextuser) {
$fullname = fullname($contextuser, true);
$timeend = optional_param('timened', 0, PARAM_INT);
$userid = optional_param('userid', 0, PARAM_INT); // needed for user tabs
$courseid = optional_param('courseid', 0, PARAM_INT); // needed for user tabs
-
+
$errors = array();
$previoussearch = ($searchtext != '') or ($previoussearch) ? 1:0;
}
} else {
$courseid = SITEID;
- $course = get_site();
+ $course = clone($SITE);
}
+ require_login($course);
+
if ($context->contextlevel == CONTEXT_COURSE) {
require_login($context->instanceid);
} else {
require_capability('moodle/role:assign', $context);
- $assignableroles = get_assignable_roles($context);
+/// needed for tabs.php
+ $overridableroles = get_overridable_roles($context);
+ $assignableroles = get_assignable_roles($context);
+
/// Get some language strings
$strassignusers = get_string('assignusers', 'role');
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
$topleveladmin = false;
-
+
// we only worry about this if the role has doanything capability at site level
if ($context->id == $sitecontext->id && $adminroles = get_roles_with_capability('moodle/site:doanything', CAP_ALLOW, $sitecontext)) {
foreach ($adminroles as $adminrole) {
}
}
}
-
+
foreach ($frm->removeselect as $removeuser) {
$removeuser = clean_param($removeuser, PARAM_INT);
}
$select = "username <> 'guest' AND deleted = 0 AND confirmed = 1";
-
+
$usercount = count_records_select('user', $select) - count($contextusers);
$searchtext = trim($searchtext);
$select .= " AND ($FULLNAME $LIKE '%$searchtext%' OR email $LIKE '%$searchtext%') ";
}
- $availableusers = get_recordset_sql('SELECT id, firstname, lastname, email
- FROM '.$CFG->prefix.'user
+ $availableusers = get_recordset_sql('SELECT id, firstname, lastname, email
+ FROM '.$CFG->prefix.'user
WHERE '.$select.'
ORDER BY lastname ASC, firstname ASC');
/// In the .html file below we loop through these results and exclude any in $contextusers
echo '<div style="text-align:center">'.$strcurrentcontext.': '.print_context_name($context).'<br/>';
- echo '<label>'.$strroletoassign.'</label>: ';
- $assignableroles = array('0'=>get_string('listallroles', 'role').'...') + $assignableroles;
+ $assignableroles = array('0'=>get_string('listallroles', 'role').'...') + $assignableroles;
popup_form("$CFG->wwwroot/$CFG->admin/roles/assign.php?userid=$userid&courseid=$courseid&contextid=$contextid&roleid=",
- $assignableroles, 'switchrole', $roleid, '');
+ $assignableroles, 'switchrole', $roleid, '', '', '', false, 'self', $strroletoassign);
echo '</div>';
print_simple_box_start('center');
<input type="hidden" name="sesskey" value="<?php p(sesskey()) ?>" />
<input type="hidden" name="action" value="<?php if ($action != 'view') { echo p($action); } ?>" />
</fieldset>
-<table cellpadding="9" cellspacing="0" align="center">
+<table class="roledesc" cellpadding="9" cellspacing="0">
<?php if ($action == 'view') { ?>
<tr valign="top">
<td align="right"><?php print_string('name') ?>:</td>
$strprohibit = get_string('prohibit','role');
?>
-<table class="rolecap" align="center">
+<table class="rolecap">
<tr>
<th class="name" align="left" scope="col"><?php print_string('capability','role') ?></th>
$riskinfo = '<td class="risk managetrust">';
$rowclasses = '';
if (RISK_MANAGETRUST & (int)$capability->riskbitmask) {
- $riskinfo .= '<a target="docspopup" title="'.get_string('riskmanagetrust', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">';
+ $riskinfo .= '<a onclick="this.target=\'docspopup\'" title="'.get_string('riskmanagetrust', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">';
$riskinfo .= '<img src="'.$CFG->pixpath.'/i/risk_managetrust.gif" alt="'.get_string('riskmanagetrustshort', 'admin').'" /></a>';
$rowclasses .= ' riskmanagetrust';
}
$riskinfo .= '</td><td class="risk config">';
if (RISK_CONFIG & (int)$capability->riskbitmask) {
- $riskinfo .= '<a target="docspopup" title="'.get_string('riskconfig', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">';
+ $riskinfo .= '<a onclick="this.target=\'docspopup\'" title="'.get_string('riskconfig', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">';
$riskinfo .= '<img src="'.$CFG->pixpath.'/i/risk_config.gif" alt="'.get_string('riskconfigshort', 'admin').'" /></a>';
$rowclasses .= ' riskconfig';
}
$riskinfo .= '</td><td class="risk xss">';
if (RISK_XSS & (int)$capability->riskbitmask) {
- $riskinfo .= '<a target="docspopup" title="'.get_string('riskxss', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">';
+ $riskinfo .= '<a onclick="this.target=\'docspopup\'" title="'.get_string('riskxss', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">';
$riskinfo .= '<img src="'.$CFG->pixpath.'/i/risk_xss.gif" alt="'.get_string('riskxssshort', 'admin').'" /></a>';
$rowclasses .= ' riskxss';
}
$riskinfo .= '</td><td class="risk personal">';
if (RISK_PERSONAL & (int)$capability->riskbitmask) {
- $riskinfo .= '<a target="docspopup" title="'.get_string('riskpersonal', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">';
+ $riskinfo .= '<a onclick="this.target=\'docspopup\'" title="'.get_string('riskpersonal', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">';
$riskinfo .= '<img src="'.$CFG->pixpath.'/i/risk_personal.gif" alt="'.get_string('riskpersonalshort', 'admin').'" /></a>';
$rowclasses .= ' riskpersonal';
}
$riskinfo .= '</td><td class="risk spam">';
if (RISK_SPAM & (int)$capability->riskbitmask) {
- $riskinfo .= '<a target="docspopup" title="'.get_string('riskspam', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">';
+ $riskinfo .= '<a onclick="this.target=\'docspopup\'" title="'.get_string('riskspam', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">';
$riskinfo .= '<img src="'.$CFG->pixpath.'/i/risk_spam.gif" alt="'.get_string('riskspamshort', 'admin').'" /></a>';
$rowclasses .= ' riskspam';
}
?>
<tr class="rolecap <?php echo $rowclasses; ?>">
- <td class="name"><span class="cap-desc"><a target="docspopup" href="<?php echo $CFG->docroot.'/'.$lang.'/'.$strcapabilities.'/'.$capability->name ?>"><?php echo get_capability_string($capability->name); ?></a><span class="cap-name"><?php echo $capability->name ?></span></span></td>
+ <td class="name"><span class="cap-desc"><a onclick="this.target='docspopup'" href="<?php echo $CFG->docroot.'/'.$lang.'/'.$strcapabilities.'/'.$capability->name ?>"><?php echo get_capability_string($capability->name); ?></a><span class="cap-name"><?php echo $capability->name ?></span></span></td>
<td class="inherit <?php echo $isinherit ?>">
<input type="radio" title="<?php p($strinherit); ?>" name="<?php echo $capability->name; ?>" value="<?php echo CAP_INHERIT ?>" <?php if (!isset($localoverride->permission) || $localoverride->permission==CAP_INHERIT){ echo 'checked="checked"'; }?> <?php echo $disabled; ?>/></td>
<td class="allow <?php echo $isallow ?>">
$confirm = optional_param('confirm', 0, PARAM_BOOL);
$cancel = optional_param('cancel', 0, PARAM_BOOL);
- $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
+ $sitecontext = get_context_instance(CONTEXT_SYSTEM);
require_capability('moodle/role:manage', $sitecontext);
}
if ($confirm and data_submitted() and confirm_sesskey()) {
- $legacyroles = get_legacy_roles();
-
- $defaultcaps = array();
- foreach($legacyroles as $ltype=>$lcap) {
- $localoverride = get_local_override($roleid, $sitecontext->id, $lcap);
- if (!empty($localoverride->permission) and $localoverride->permission == CAP_ALLOW) {
- //choose first selected legacy capability
- $defaultcaps = get_default_capabilities($ltype);
- break;
- }
- }
-
- delete_records('role_capabilities', 'roleid', $roleid);
- if (!empty($defaultcaps)) {
- foreach($defaultcaps as $cap=>$permission) {
- assign_capability($cap, $permission, $roleid, $sitecontext->id);
- }
- }
+ reset_role_capabilities($roleid);
redirect('manage.php?action=view&roleid='.$roleid);
} else {
$options = new object();
$options->action = 'add';
+ echo '<div class="buttons">';
print_single_button('manage.php', $options, get_string('addrole', 'role'), 'get');
+ echo '</div>';
}
admin_externalpage_print_footer($adminroot);
<?php
// this page deals with the 2 tabs for manage.php and grant.php
+ if (!defined('MOODLE_INTERNAL')) {
+ die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
+ }
+
+ $toprow = array();
+
$toprow[] = new tabobject('manage', $CFG->wwwroot.'/'.$CFG->admin.'/roles/manage.php', get_string('manageroles', 'role'),'', true);
$toprow[] = new tabobject('allowassign', $CFG->wwwroot.'/'.$CFG->admin.'/roles/allowassign.php', get_string('allowassign', 'role'));
?>
<form id="overrideform" action="override.php" method="post">
+ <fieldset class="invisiblefieldset">
<input type="hidden" name="contextid" value="<?php p($contextid) ?>" />
<input type="hidden" name="roleid" value="<?php p($roleid) ?>" />
<input type="hidden" name="sesskey" value="<?php p(sesskey()) ?>" />
<input type="hidden" name="userid" value="<?php p($userid) ?>" />
<input type="hidden" name="courseid" value="<?php p($courseid) ?>" />
+ </fieldset>
<table class="rolecap">
<tr>
$riskinfo = '<td class="risk managetrust">';
$rowclasses = '';
if (RISK_MANAGETRUST & (int)$capability->riskbitmask) {
- $riskinfo .= '<a target="docspopup" title="'.get_string('riskmanagetrust', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">';
+ $riskinfo .= '<a onclick="this.target=\'docspopup\'" title="'.get_string('riskmanagetrust', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">';
$riskinfo .= '<img src="'.$CFG->pixpath.'/i/risk_managetrust.gif" alt="'.get_string('riskmanagetrustshort', 'admin').'" /></a>';
$rowclasses .= ' riskmanagetrust';
}
$riskinfo .= '</td><td class="risk config">';
if (RISK_CONFIG & (int)$capability->riskbitmask) {
- $riskinfo .= '<a target="docspopup" title="'.get_string('riskconfig', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">';
+ $riskinfo .= '<a onclick="this.target=\'docspopup\'" title="'.get_string('riskconfig', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">';
$riskinfo .= '<img src="'.$CFG->pixpath.'/i/risk_config.gif" alt="'.get_string('riskconfigshort', 'admin').'" /></a>';
$rowclasses .= ' riskconfig';
}
$riskinfo .= '</td><td class="risk xss">';
if (RISK_XSS & (int)$capability->riskbitmask) {
- $riskinfo .= '<a target="docspopup" title="'.get_string('riskxss', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">';
+ $riskinfo .= '<a onclick="this.target=\'docspopup\'" title="'.get_string('riskxss', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">';
$riskinfo .= '<img src="'.$CFG->pixpath.'/i/risk_xss.gif" alt="'.get_string('riskxssshort', 'admin').'" /></a>';
$rowclasses .= ' riskxss';
}
$riskinfo .= '</td><td class="risk personal">';
if (RISK_PERSONAL & (int)$capability->riskbitmask) {
- $riskinfo .= '<a target="docspopup" title="'.get_string('riskpersonal', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">';
+ $riskinfo .= '<a onclick="this.target=\'docspopup\'" title="'.get_string('riskpersonal', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">';
$riskinfo .= '<img src="'.$CFG->pixpath.'/i/risk_personal.gif" alt="'.get_string('riskpersonalshort', 'admin').'" /></a>';
$rowclasses .= ' riskpersonal';
}
$riskinfo .= '</td><td class="risk spam">';
if (RISK_SPAM & (int)$capability->riskbitmask) {
- $riskinfo .= '<a target="docspopup" title="'.get_string('riskspam', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">';
+ $riskinfo .= '<a onclick="this.target=\'docspopup\'" title="'.get_string('riskspam', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">';
$riskinfo .= '<img src="'.$CFG->pixpath.'/i/risk_spam.gif" alt="'.get_string('riskspamshort', 'admin').'" /></a>';
$rowclasses .= ' riskspam';
}
?>
<tr class="rolecap <?php echo $rowclasses; ?>">
- <td class="name">
- <span class="cap-desc">
- <a target="docspopup" href="<?php echo $CFG->docroot.'/'.$lang.'/'.$strcapabilities.'/'.$capability->name ?>">
- <?php echo get_capability_string($capability->name); ?></a>
- </span>
- <span class="cap-name"><?php echo $capability->name ?></span>
- </td>
+ <td class="name"><span class="cap-desc"><a onclick="this.target='docspopup'" href="<?php echo $CFG->docroot.'/'.$lang.'/'.$strcapabilities.'/'.$capability->name ?>"><?php echo get_capability_string($capability->name); ?></a><span class="cap-name"><?php echo $capability->name ?></span></span></td>
<td class="inherit">
<input type="radio" title="<?php p($strinherit); ?>" name="<?php echo $capability->name; ?>" value="0"
<?php } ?>
</table>
- <br />
- <div align="center">
+ <div class="submit buttons">
<input type="submit" value="<?php print_string('savechanges') ?>" />
<input type="submit" name="cancel" value="<?php print_string('cancel') ?>" />
</div>
require_once('../../config.php');
- $contextid = required_param('contextid',PARAM_INT); // context id
+ $contextid = required_param('contextid', PARAM_INT); // context id
$roleid = optional_param('roleid', 0, PARAM_INT); // requested role id
$userid = optional_param('userid', 0, PARAM_INT); // needed for user tabs
$courseid = optional_param('courseid', 0, PARAM_INT); // needed for user tabs
error('Bad context ID');
}
- if (!$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID)) {
+ if (!$sitecontext = get_context_instance(CONTEXT_SYSTEM)) {
error('No site ID');
}
if ($context->id == $sitecontext->id) {
- error ('Can not override base role capabilities');
+ error('Can not override base role capabilities');
}
- require_capability('moodle/role:override', $context); // Just to make sure
+ if (!has_capability('moodle/role:override', $context)) {
+ error('You do not have permission to change overrides in this context!');
+ }
if ($courseid) {
if (!$course = get_record('course', 'id', $courseid)) {
error('Bad course ID');
}
} else {
- $course = $SITE;
+ $course = clone($SITE);
+ $courseid = SITEID;
}
+ require_login($course);
+
$baseurl = 'override.php?contextid='.$context->id;
if (!empty($userid)) {
$baseurl .= '&userid='.$userid;
}
- if (!empty($courseid)) {
+ if ($courseid != SITEID) {
$baseurl .= '&courseid='.$courseid;
}
redirect($baseurl);
}
+/// needed for tabs.php
+ $overridableroles = get_overridable_roles($context);
+ $assignableroles = get_assignable_roles($context);
/// Get some language strings
$strparticipants = get_string('participants');
/// Make sure this user can override that role
+
if ($roleid) {
if (!user_can_override($context, $roleid)) {
error ('you can not override this role in this context');
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context));
}
+/// get all cababilities
+ $capabilities = fetch_context_capabilities($context);
+
/// Process incoming role override
if ($data = data_submitted() and $roleid and confirm_sesskey()) {
$allowed_values = array(CAP_INHERIT, CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT);
- $capabilities = fetch_context_capabilities($context); // capabilities applicable in this context
$localoverrides = get_records_select('role_capabilities', "roleid = $roleid AND contextid = $context->id",
'', 'capability, permission, id');
foreach ($capabilities as $cap) {
+
if (!isset($data->{$cap->name})) {
+ //cap not specified in form
continue;
}
+
$capname = $cap->name;
$value = clean_param($data->{$cap->name}, PARAM_INT);
if (!in_array($value, $allowed_values)) {
print_heading_with_help(get_string('overrides', 'role'), 'overrides');
- $overridableroles = get_overridable_roles($context);
-
if ($roleid) {
/// prints a form to swap roles
- echo '<div align="center">'.$strcurrentcontext.': '.print_context_name($context).'<br/>';
- echo $strroletooverride.': ';
- $overridableroles = array('0'=>get_string('listallroles', 'role').'...') + $overridableroles;
+ echo '<div class="selector">';
+ echo $strcurrentcontext.': '.print_context_name($context).'<br/>';
+ $overridableroles = array('0'=>get_string('listallroles', 'role').'...') + $overridableroles;
popup_form("$CFG->wwwroot/$CFG->admin/roles/override.php?userid=$userid&courseid=$courseid&contextid=$contextid&roleid=",
- $overridableroles, 'switchrole', $roleid, '');
+ $overridableroles, 'switchrole', $roleid, '', '', '', false, 'self', $strroletooverride);
echo '</div>';
$parentcontexts = get_parent_contexts($context);
$lang = str_replace('_utf8', '', current_language());
- // Get the capabilities overrideable in this context
- if ($capabilities = fetch_context_capabilities($context)) {
+ if (!empty($capabilities)) {
+ // Print the capabilities overrideable in this context
print_simple_box_start('center');
include_once('override.html');
print_simple_box_end();
+
} else {
notice(get_string('nocapabilitiesincontext', 'role'),
$CFG->wwwroot.'/'.$CFG->admin.'/roles/'.$baseurl);
<?php // $Id$
// Handles headers and tabs for the roles control at any level apart from SYSTEM level
+// We also assume that $currenttab, $assignableroles and $overridableroles are defined
+
+if (!defined('MOODLE_INTERNAL')) {
+ die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
+}
if ($currenttab != 'update') {
switch ($context->contextlevel) {
case CONTEXT_COURSE:
if ($context->instanceid != SITEID) {
$streditcoursesettings = get_string("editcoursesettings");
-
+
$course = get_record('course', 'id', $context->instanceid);
+
+ require_login($course);
+
print_header($streditcoursesettings, $course->fullname,
"<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> -> $straction");
- }
+ }
break;
case CONTEXT_GROUP:
error("The required instance of this module doesn't exist");
}
+ require_login($course);
+
$strnav = "<a href=\"$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id\">$instance->name</a> ->";
$fullmodulename = get_string("modulename", $module->name);
$streditinga = get_string("editinga", "moodle", $fullmodulename);
$focuscursor = "form.name";
}
- $COURSE = $course;
print_header_simple($streditinga, '',
"<a href=\"$CFG->wwwroot/mod/$module->name/index.php?id=$course->id\">$strmodulenameplural</a> ->
$strnav <a href=\"$CFG->wwwroot/course/mod.php?update=$cm->id&sesskey=".sesskey()."\">$streditinga</a> -> $straction", $focuscursor, "", false);
switch ($blockinstance->pagetype) {
case 'course-view':
if ($course = get_record('course', 'id', $blockinstance->pageid)) {
+
+ require_login($course);
+
if ($course->id != SITEID) {
$navigation = "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> -> $navigation";
}
$toprow[] = new tabobject('roles', $CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.
$context->id, get_string('roles'));
- if (isset($tabsmode)) {
-
- if (!isset($assignableroles)) {
- $assignableroles = get_assignable_roles($context);
- }
- if (!isset($overridableroles)) {
- $overridableroles = get_overridable_roles($context);
- }
+ if (!empty($tabsmode)) {
if (!empty($assignableroles)) {
$secondrow[] = new tabobject('assign',
function init() {
$this->title = get_string('feedstitle', 'block_rss_client');
- $this->version = 2006100101;
+ $this->version = 2006100102;
}
function preferred_width() {
'block/rss_client:createsharedfeeds' => array(
+ 'riskbitmask' => RISK_SPAM,
+
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'legacy' => array(
'block/rss_client:manageanyfeeds' => array(
+ 'riskbitmask' => RISK_SPAM,
+
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'legacy' => array(
$enrol_authorize_capabilities = array(
'enrol/authorize:managepayments' => array(
+ 'riskbitmask' => RISK_PERSONAL,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'legacy' => array(
<?php // $Id$
-$plugin->version = 2006112900;
+$plugin->version = 2006112901;
$plugin->requires = 2006100401;
?>
}
-/*
+/**
* auxillary function for load_user_capabilities()
* handler in usort() to sort contexts according to level
* @param object contexta
}
-/*
+/**
* Check all the login enrolment information for the given user object
* by querying the enrolment plugins
*/
'editingteacher' => 'moodle/legacy:editingteacher',
'teacher' => 'moodle/legacy:teacher',
'student' => 'moodle/legacy:student',
- 'user' => 'moodle/legacy:user',
- 'guest' => 'moodle/legacy:guest'
+ 'guest' => 'moodle/legacy:guest',
+ 'user' => 'moodle/legacy:user'
);
}
}
}
-/*
+/**
* This hacky function is needed because we can not change system context instanceid using normal upgrade routine.
*/
function create_system_context() {
return $success;
}
-/*
+/**
* A convenience function to take care of the common case where you
* just want to enrol someone using the default role into a course
*
$defaults = array();
$components = array();
foreach ($allcaps as $cap) {
- if (!array_search($cap->component, $components)) {
+ if (!in_array($cap->component, $components)) {
$components[] = $cap->component;
$alldefs = array_merge($alldefs, load_capability_def($cap->component));
}
return $defaults;
}
+/**
+ * Reset role capabilitites to default according to selected legacy capability.
+ * If several legacy caps selected, use the first from get_default_capabilities.
+ * If no legacy selected, removes all capabilities.
+ *
+ * @param int @roleid
+ */
+function reset_role_capabilities($roleid) {
+ $sitecontext = get_context_instance(CONTEXT_SYSTEM);
+ $legacyroles = get_legacy_roles();
+
+ $defaultcaps = array();
+ foreach($legacyroles as $ltype=>$lcap) {
+ $localoverride = get_local_override($roleid, $sitecontext->id, $lcap);
+ if (!empty($localoverride->permission) and $localoverride->permission == CAP_ALLOW) {
+ //choose first selected legacy capability
+ $defaultcaps = get_default_capabilities($ltype);
+ break;
+ }
+ }
+
+ delete_records('role_capabilities', 'roleid', $roleid);
+ if (!empty($defaultcaps)) {
+ foreach($defaultcaps as $cap=>$permission) {
+ assign_capability($cap, $permission, $roleid, $sitecontext->id);
+ }
+ }
+}
+
/**
* Updates the capabilities table with the component capability definitions.
* If no parameters are given, the function updates the core moodle
* @param object $context
* @return array
*/
-function get_overridable_roles ($context) {
+function get_overridable_roles($context) {
$options = array();
return $options;
}
-/*
+/**
* Returns a role object that is the default role for new enrolments
* in a given course
*
}
-/*
+/**
* Switches the current user to another role for the current session and only
* in the given context. If roleid is not valid (eg 0) or the current user
* doesn't have permissions to be switching roles then the user's session
-/* find all user assignemnt of users for this role, on this context
+/**
+ * Find all user assignemnt of users for this role, on this context
*/
function get_users_from_role_on_context($role, $context) {
AND roleid = $role->id");
}
-/*
+/**
* Simple function returning a boolean true if roles exist, otherwise false
*/
function user_has_role_assignment($userid, $roleid, $contextid=0) {
}
}
-// inserts all parental context and self into context_rel table
-/** @param object $context-context to be deleted
+/**
+ * Inserts all parental context and self into context_rel table
+ *
+ * @param object $context-context to be deleted
* @param bool deletechild - deltes child contexts dependencies
*/
function insert_context_rel($context, $deletechild=true, $deleteparent=true) {
}
}
-// rebuild context_rel table without deleting
+
+/**
+ * rebuild context_rel table without deleting
+ */
function build_context_rel() {
global $db;
}
}
+ if ($result && $oldversion < 2007021401) {
+ /// create default logged in user role if not present - upgrade rom 1.7.x
+ if (empty($CFG->defaultuserroleid) or $CFG->defaultuserroleid == $CFG->guestroleid) {
+ if (!get_records('role', 'shortname', 'user')) {
+ $userroleid = create_role(addslashes(get_string('authenticateduser')), 'user',
+ addslashes(get_string('authenticateduserdescription')), 'moodle/legacy:user');
+ if ($userroleid) {
+ reset_role_capabilities($userroleid);
+ set_config('defaultuserroleid', $userroleid);
+ }
+ }
+ }
+ }
+
return $result;
}
'mod/data:manageuserpresets' => array(
+ 'riskbitmask' => RISK_SPAM | RISK_XSS,
+
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'legacy' => array(
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
-$module->version = 2007022600;
+$module->version = 2007022601;
$module->requires = 2007020200; // Requires this Moodle version
$module->cron = 60;
margin-top: 1em;
}
-#admin-roles-manage .buttons {
+#admin-roles-allowassign .buttons,
+#admin-roles-allowoverride .buttons,
+#admin-roles-manage .buttons,
+#admin-roles-override .buttons {
margin: 20px;
text-align:center;
}
-#admin-roles-manage .buttons .singlebutton {
- display: inline;
+#admin-roles-manage .buttons .singlebutton,
+#admin-roles-override .buttons .singlebutton {
+ display: inline;
+ padding: 5px;
}
-#admin-roles-manage .singlebutton,
-#admin-roles-allowoverride .singlebutton,
-#admin-roles-allowassign .singlebutton {
- padding: 5px;
- text-align:center;
+#admin-roles-manage .selector,
+#admin-roles-override .selector {
+ text-align:center;
}
-#admin-roles-manage .selector {
- text-align:center;
+#admin-roles-manage table.roledesc,
+#admin-roles-override table.roledesc {
+ margin-left:auto;
+ margin-right:auto;
+}
+
+#admin-roles-manage table.rolecap,
+#admin-roles-override table.rolecap {
+ margin-left:auto;
+ margin-right:auto;
}
.rolecap .inherit,
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
- $version = 2007021400; // YYYYMMDD = date
+ $version = 2007021401; // YYYYMMDD = date
// XY = increments within a single day
$release = '1.9 dev'; // Human-friendly version name