mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
partial rewrite of role manage script, improved notice_yesno(), other minor fixes and changes; I will work on assign and overide tomorrow ;-)
This commit is contained in:
parent
e78a3505c5
commit
b5959f3071
8 changed files with 413 additions and 133 deletions
|
@ -1188,7 +1188,7 @@ function get_local_override($roleid, $contextid, $capability) {
|
|||
* @param legacy - optional legacy capability
|
||||
* @return id or false
|
||||
*/
|
||||
function create_role($name, $shortname, $description, $legacy='') {
|
||||
function create_role($name, $shortname, $description, $legacy='', $sortorder = -1) {
|
||||
|
||||
// check for duplicate role name
|
||||
|
||||
|
@ -1200,10 +1200,17 @@ function create_role($name, $shortname, $description, $legacy='') {
|
|||
error('there is already a role with this shortname!');
|
||||
}
|
||||
|
||||
$role = new object();
|
||||
$role->name = $name;
|
||||
$role->shortname = $shortname;
|
||||
$role->description = $description;
|
||||
|
||||
if ($sortorder = -1) {
|
||||
$role->sortorder = count_records('role');
|
||||
} else {
|
||||
$role->sortorder = $sortorder;
|
||||
}
|
||||
|
||||
$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
||||
|
||||
if ($id = insert_record('role', $role)) {
|
||||
|
@ -2626,21 +2633,21 @@ function get_user_capability_course($capability, $userid='') {
|
|||
* @return array
|
||||
*/
|
||||
function get_roles_on_exact_context($context) {
|
||||
|
||||
|
||||
global $CFG;
|
||||
|
||||
return get_records_sql("SELECT DISTINCT r.*
|
||||
return get_records_sql("SELECT DISTINCT r.*
|
||||
FROM {$CFG->prefix}role_assignments ra,
|
||||
{$CFG->prefix}role r
|
||||
WHERE ra.roleid = r.id
|
||||
AND ra.contextid = $context->id");
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* 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
|
||||
* 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
|
||||
* is compltely reset to have their normal roles.
|
||||
* @param integer $roleid
|
||||
* @param object $context
|
||||
|
@ -2652,7 +2659,7 @@ function role_switch($roleid, $context) {
|
|||
global $db;
|
||||
|
||||
/// If we can't use this or are already using it or no role was specified then bail completely and reset
|
||||
if (empty($roleid) || !has_capability('moodle/role:switchroles', $context)
|
||||
if (empty($roleid) || !has_capability('moodle/role:switchroles', $context)
|
||||
|| !empty($USER->switchrole[$context->id]) || !confirm_sesskey()) {
|
||||
load_user_capability('', $context); // Reset all permissions for this context to normal
|
||||
unset($USER->switchrole[$context->id]); // Delete old capabilities
|
||||
|
@ -2695,9 +2702,9 @@ function role_switch($roleid, $context) {
|
|||
|
||||
// get any role that has an override on exact context
|
||||
function get_roles_with_override_on_context($context) {
|
||||
|
||||
|
||||
global $CFG;
|
||||
|
||||
|
||||
return get_records_sql("SELECT DISTINCT r.*
|
||||
FROM {$CFG->prefix}role_capabilities rc,
|
||||
{$CFG->prefix}role r
|
||||
|
@ -2707,10 +2714,10 @@ function get_roles_with_override_on_context($context) {
|
|||
|
||||
// get all capabilities for this role on this context (overrids)
|
||||
function get_capabilities_from_role_on_context($role, $context) {
|
||||
|
||||
|
||||
global $CFG;
|
||||
|
||||
return get_records_sql("SELECT *
|
||||
|
||||
return get_records_sql("SELECT *
|
||||
FROM {$CFG->prefix}role_capabilities
|
||||
WHERE contextid = $context->id
|
||||
AND roleid = $role->id");
|
||||
|
@ -2719,13 +2726,13 @@ function get_capabilities_from_role_on_context($role, $context) {
|
|||
/* find all user assignemnt of users for this role, on this context
|
||||
*/
|
||||
function get_users_from_role_on_context($role, $context) {
|
||||
|
||||
|
||||
global $CFG;
|
||||
|
||||
|
||||
return get_records_sql("SELECT *
|
||||
FROM {$CFG->prefix}role_assignments
|
||||
WHERE contextid = $context->id
|
||||
AND roleid = $role->id");
|
||||
AND roleid = $role->id");
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -381,7 +381,6 @@ function upgrade_activity_modules($return) {
|
|||
|
||||
if ($updated_modules) {
|
||||
print_continue($return);
|
||||
print_footer();
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4600,7 +4600,7 @@ function notice ($message, $link='') {
|
|||
* @param string $linkyes The link to take the user to if they choose "Yes"
|
||||
* @param string $linkno The link to take the user to if they choose "No"
|
||||
*/
|
||||
function notice_yesno ($message, $linkyes, $linkno) {
|
||||
function notice_yesno ($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno=NULL, $methodyes='post', $methodno='post') {
|
||||
|
||||
global $CFG;
|
||||
|
||||
|
@ -4611,9 +4611,9 @@ function notice_yesno ($message, $linkyes, $linkno) {
|
|||
print_simple_box_start('center', '60%', '', 5, 'generalbox', 'notice');
|
||||
echo '<p align="center">'. $message .'</p>';
|
||||
echo '<table align="center" cellpadding="20"><tr><td>';
|
||||
print_single_button($linkyes, NULL, get_string('yes'), 'post', $CFG->framename);
|
||||
print_single_button($linkyes, $optionsyes, get_string('yes'), $methodyes, $CFG->framename);
|
||||
echo '</td><td>';
|
||||
print_single_button($linkno, NULL, get_string('no'), 'post', $CFG->framename);
|
||||
print_single_button($linkno, $optionsno, get_string('no'), $methodno, $CFG->framename);
|
||||
echo '</td></tr></table>';
|
||||
print_simple_box_end();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue