/** * Constructor. * @throws Command_Exception. */ public function __construct() { global $DB; // Getting command description. $cmd_name = vmoodle_get_string('cmdsynccapabilityname', 'vmoodleadminset_roles'); $cmd_desc = vmoodle_get_string('cmdsynccapabilitydesc', 'vmoodleadminset_roles'); // Creating platform parameter. $platform_param = new Command_Parameter('platform', 'enum', vmoodle_get_string('platformparamsyncdesc', 'vmoodleadminset_roles'), null, get_available_platforms()); // Getting role parameter. $roles = role_fix_names(get_all_roles(), \context_system::instance(), ROLENAME_ORIGINAL); $rolemenu = array(); foreach ($roles as $r) { $rolemenu[$r->shortname] = $r->name; } $role_param = new Command_Parameter('role', 'enum', vmoodle_get_string('roleparamsyncdesc', 'vmoodleadminset_roles'), null, $rolemenu); // Creating capability parameter. $records = $DB->get_records('capabilities', null, 'name', 'name'); $capabilities = array(); foreach ($records as $record) { $capabilities[$record->name] = get_capability_string($record->name); } asort($capabilities); $capability_param = new Command_Parameter('capability', 'enum', vmoodle_get_string('capabilityparamsyncdesc', 'vmoodleadminset_roles'), null, $capabilities); // Creating command. parent::__construct($cmd_name, $cmd_desc, array($platform_param, $role_param, $capability_param)); }
protected function get_capabitity_optgroups() { if (!empty($this->_optGroups)) { // I have absolutely no idea why this is necessary, but it does seem to be. // Bloody formslib. Somehow it is calling the constructor twice. return array(); } $optgroups = array(); $capabilities = context_system::instance()->get_capabilities(); $contextlevel = 0; $component = ''; $currentgroup = array(); $currentgroupname = ''; foreach ($capabilities as $capability) { // Start a new optgroup if the componentname or context level has changed. if (component_level_changed($capability, $component, $contextlevel)) { if ($currentgroup) { $optgroups[$currentgroupname] = $currentgroup; } $currentgroup = array(); $currentgroupname = context_helper::get_level_name($capability->contextlevel) . ': ' . get_component_string($capability->component, $capability->contextlevel); } $contextlevel = $capability->contextlevel; $component = $capability->component; $a = new stdClass(); $a->name = get_capability_string($capability->name); $a->capabilityname = $capability->name; $currentgroup[$capability->name] = get_string('capabilityandname', 'tool_editrolesbycap', $a); } // Remeber to add the currently open optgroup. if ($currentgroup) { $optgroups[$currentgroupname] = $currentgroup; } return $optgroups; }
function definition() { $mform = $this->_form; $service = isset($this->_customdata) ? $this->_customdata : new stdClass(); $mform->addElement('header', 'extservice', get_string('externalservice', 'webservice')); $mform->addElement('text', 'name', get_string('name')); $mform->addRule('name', get_string('required'), 'required', null, 'client'); $mform->setType('name', PARAM_TEXT); $mform->addElement('advcheckbox', 'enabled', get_string('enabled', 'webservice')); $mform->setType('enabled', PARAM_BOOL); $mform->addElement('advcheckbox', 'restrictedusers', get_string('restrictedusers', 'webservice')); $mform->addHelpButton('restrictedusers', 'restrictedusers', 'webservice'); $mform->setType('restrictedusers', PARAM_BOOL); // Can users download files? $mform->addElement('advcheckbox', 'downloadfiles', get_string('downloadfiles', 'webservice')); $mform->setAdvanced('downloadfiles'); $mform->addHelpButton('downloadfiles', 'downloadfiles', 'webservice'); $mform->setType('downloadfiles', PARAM_BOOL); // Can users upload files? $mform->addElement('advcheckbox', 'uploadfiles', get_string('uploadfiles', 'webservice')); $mform->setAdvanced('uploadfiles'); $mform->addHelpButton('uploadfiles', 'uploadfiles', 'webservice'); /// needed to select automatically the 'No required capability" option $currentcapabilityexist = false; if (empty($service->requiredcapability)) { $service->requiredcapability = "norequiredcapability"; $currentcapabilityexist = true; } // Prepare the list of capabilities to choose from $systemcontext = context_system::instance(); $allcapabilities = $systemcontext->get_capabilities(); $capabilitychoices = array(); $capabilitychoices['norequiredcapability'] = get_string('norequiredcapability', 'webservice'); foreach ($allcapabilities as $cap) { $capabilitychoices[$cap->name] = $cap->name . ': ' . get_capability_string($cap->name); if (!empty($service->requiredcapability) && $service->requiredcapability == $cap->name) { $currentcapabilityexist = true; } } $mform->addElement('searchableselector', 'requiredcapability', get_string('requiredcapability', 'webservice'), $capabilitychoices); $mform->addHelpButton('requiredcapability', 'requiredcapability', 'webservice'); $mform->setAdvanced('requiredcapability'); $mform->setType('requiredcapability', PARAM_RAW); /// display notification error if the current requiredcapability doesn't exist anymore if (empty($currentcapabilityexist)) { global $OUTPUT; $mform->addElement('static', 'capabilityerror', '', $OUTPUT->notification(get_string('selectedcapabilitydoesntexit', 'webservice', $service->requiredcapability))); $service->requiredcapability = "norequiredcapability"; } $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); if (!empty($service->id)) { $buttonlabel = get_string('savechanges'); } else { $buttonlabel = get_string('addaservice', 'webservice'); } $this->add_action_buttons(true, $buttonlabel); $this->set_data($service); }
/** * Produces a table to visually compare roles and capabilities. * * @param array $capabilities An array of capabilities to show comparison for. * @param int $contextid The context we are displaying for. * @param array $roles An array of roles to show comparison for. * @return string */ public function capability_comparison_table(array $capabilities, $contextid, array $roles) { $strpermissions = $this->get_permission_strings(); $permissionclasses = $this->get_permission_classes(); if ($contextid === context_system::instance()->id) { $strpermissions[CAP_INHERIT] = new lang_string('notset', 'role'); } $table = new html_table(); $table->attributes['class'] = 'comparisontable'; $table->head = array(' '); foreach ($roles as $role) { $url = new moodle_url('/admin/roles/define.php', array('action' => 'view', 'roleid' => $role->id)); $table->head[] = html_writer::div(html_writer::link($url, $role->localname)); } $table->data = array(); foreach ($capabilities as $capability) { $contexts = tool_capability_calculate_role_data($capability, $roles); $captitle = new html_table_cell(get_capability_string($capability) . html_writer::span($capability)); $captitle->header = true; $row = new html_table_row(array($captitle)); foreach ($roles as $role) { if (isset($contexts[$contextid]->rolecapabilities[$role->id])) { $permission = $contexts[$contextid]->rolecapabilities[$role->id]; } else { $permission = CAP_INHERIT; } $cell = new html_table_cell($strpermissions[$permission]); $cell->attributes['class'] = $permissionclasses[$permission]; $row->cells[] = $cell; } $table->data[] = $row; } // Start the list item, and print the context name as a link to the place to make changes. if ($contextid == context_system::instance()->id) { $url = new moodle_url('/admin/roles/manage.php'); $title = get_string('changeroles', 'tool_capability'); } else { $url = new moodle_url('/admin/roles/override.php', array('contextid' => $contextid)); $title = get_string('changeoverrides', 'tool_capability'); } $context = context::instance_by_id($contextid); $html = $this->output->heading(html_writer::link($url, $context->get_context_name(), array('title' => $title)), 3); $html .= html_writer::table($table); // If there are any child contexts, print them recursively. if (!empty($contexts[$contextid]->children)) { foreach ($contexts[$contextid]->children as $childcontextid) { $html .= $this->capability_comparison_table($capabilities, $childcontextid, $roles, true); } } return $html; }
/** * Outputs a matrix of roles and capabilities. * * @param int $contextid The context we are displaying for. * @param array $capabilities An array of capabilities to show. * @param array $roles An array of roles to show. */ function capability_matrix($contextid, array $capabilities, array $roles) { $strpermissions = get_permission_strings(); if ($contextid === context_system::instance()->id) { $strpermissions[CAP_INHERIT] = new lang_string('notset', 'role'); } // Start the list item. $context = context::instance_by_id($contextid); echo "\n" . $context->get_context_name() . "\t"; // Display the role names as headings. foreach ($roles as $role) { echo $role->localname . "\t"; } echo "\n\n"; $matrix = array(); foreach ($capabilities as $capability) { $contexts = tool_capability_calculate_role_data($capability, $roles); echo get_capability_string($capability) . "\t"; foreach ($roles as $role) { if (isset($contexts[$contextid]->rolecapabilities[$role->id])) { $permission = $contexts[$contextid]->rolecapabilities[$role->id]; } else { $permission = CAP_INHERIT; } echo $strpermissions[$permission] . "\t"; $matrix[$role][$capability] = $permission; // for comparison matrix !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! } echo "\n"; } // If there are any child contexts, print them recursively. if (!empty($contexts[$contextid]->children)) { foreach ($contexts[$contextid]->children as $childcontextid) { capability_comparison_table($capabilities, $childcontextid, $roles, true); } } return; }
/** * Display capabilities for role */ public function capabilities($capabilities, $roleid, $companyid) { global $DB; // get heading $company = $DB->get_record('company', array('id' => $companyid), '*', MUST_EXIST); $role = $DB->get_record('role', array('id' => $roleid), '*', MUST_EXIST); $out = '<h3>' . get_string('restrictcapabilitiesfor', 'block_iomad_company_admin', $company->name) . '</h3>'; $out .= '<p><b>' . get_string('rolename', 'block_iomad_company_admin', $role->name) . '</b></p>'; $out .= '<p>' . get_string('iomadcapabilities_boiler', 'block_iomad_company_admin') . '</p>'; $table = new html_table(); foreach ($capabilities as $capability) { $checked = ''; if (!$capability->iomad_restriction) { $checked = 'checked="checked"'; } $value = "{$companyid}.{$roleid}.{$capability->capability}"; $caplink = '<a href="' . iomad::documentation_link() . $capability->capability . '">' . get_capability_string($capability->capability) . '</a>'; $row = array($caplink . '<br /><small>' . $capability->capability . '</small>', '<input class="checkbox" type="checkbox" ' . $checked . ' value="' . $value . '" />' . get_string('allow')); $table->data[] = $row; } $out .= html_writer::table($table); return $out; }
/** * Load all of the uses who have the capability into choice array * * @return bool Always returns true */ function load_choices() { if (is_array($this->choices)) { return true; } $users = get_users_by_capability(get_context_instance(CONTEXT_SYSTEM), $this->capability, 'u.id,u.username,u.firstname,u.lastname', 'u.lastname,u.firstname'); $this->choices = array('$@NONE@$' => get_string('nobody'), '$@ALL@$' => get_string('everyonewhocan', 'admin', get_capability_string($this->capability))); if ($this->includeadmins) { $admins = get_admins(); foreach ($admins as $user) { $this->choices[$user->id] = fullname($user); } } if (is_array($users)) { foreach ($users as $user) { $this->choices[$user->id] = fullname($user); } } return true; }
/** * Load all of the uses who have the capability into choice array * * @return bool Always returns true */ function load_choices() { if (is_array($this->choices)) { return true; } list($sort, $sortparams) = users_order_by_sql('u'); if (!empty($sortparams)) { throw new coding_exception('users_order_by_sql returned some query parameters. ' . 'This is unexpected, and a problem because there is no way to pass these ' . 'parameters to get_users_by_capability. See MDL-34657.'); } $userfields = 'u.id, u.username, ' . get_all_user_name_fields(true, 'u'); $users = get_users_by_capability(context_system::instance(), $this->capability, $userfields, $sort); $this->choices = array('$@NONE@$' => get_string('nobody'), '$@ALL@$' => get_string('everyonewhocan', 'admin', get_capability_string($this->capability))); if ($this->includeadmins) { $admins = get_admins(); foreach ($admins as $user) { $this->choices[$user->id] = fullname($user); } } if (is_array($users)) { foreach ($users as $user) { $this->choices[$user->id] = fullname($user); } } return true; }
$view = 'viewowncontent'; } else { if (empty($userid) && !empty($shared)) { $sharedfiles = false; if (!empty($USER->access['rdef'])) { foreach ($USER->access['rdef'] as $ucontext) { if ($sharedfiles) { continue; } if (isset($ucontext['block/repository:viewsharedcontent']) && $ucontext['block/repository:viewsharedcontent']) { $sharedfiles = true; } } } if (!$sharedfiles) { $capabilityname = get_capability_string('block/repository:viewsharedcontent'); print_error('nopermissions', '', '', $capabilityname); exit; } if (empty($uuid)) { $uuid = $repo->suuid; } $view = 'viewsharedcontent'; } else { if (!empty($id) && empty($oid) && empty($shared) && $id != SITEID) { require_capability('block/repository:viewcoursecontent', $context, $USER->id); $view = 'viewcoursecontent'; if (empty($uuid)) { $uuid = $repo->get_course_store($id); } } else {
/** * This is an easy to use function, combining has_capability() with require_course_login(). * And will call those where needed. * * It checks for a capability assertion being true. If it isn't * then the page is terminated neatly with a standard error message. * * If the user is not logged in, or is using 'guest' access or other special "users, * it provides a logon prompt. * * @param string $capability - name of the capability * @param object $context - a context object (record from context table) * @param integer $userid - a userid number * @param bool $doanything - if false, ignore do anything * @param string $errorstring - an errorstring * @param string $stringfile - which stringfile to get it from */ function require_capability($capability, $context, $userid = NULL, $doanything = true, $errormessage = 'nopermissions', $stringfile = '') { global $USER, $CFG; /* Empty $userid means current user, if the current user is not logged in, * then make sure they are (if needed). * Originally there was a check for loaded permissions - it is not needed here. * Context is now required parameter, the cached $CONTEXT was only hiding errors. */ $errorlink = ''; if (empty($userid)) { if ($context->contextlevel == CONTEXT_COURSE) { require_login($context->instanceid); } else { if ($context->contextlevel == CONTEXT_MODULE) { if (!($cm = get_record('course_modules', 'id', $context->instanceid))) { error('Incorrect module'); } if (!($course = get_record('course', 'id', $cm->course))) { error('Incorrect course.'); } require_course_login($course, true, $cm); $errorlink = $CFG->wwwroot . '/course/view.php?id=' . $cm->course; } else { if ($context->contextlevel == CONTEXT_SYSTEM) { if (!empty($CFG->forcelogin)) { require_login(); } } else { require_login(); } } } } /// OK, if they still don't have the capability then print a nice error message if (!has_capability($capability, $context, $userid, $doanything)) { $capabilityname = get_capability_string($capability); print_error($errormessage, $stringfile, $errorlink, $capabilityname); } }
require_once dirname(__FILE__) . '/../../../config.php'; require_once $CFG->dirroot . '/' . $CFG->admin . '/tool/capability/locallib.php'; require_once $CFG->libdir . '/adminlib.php'; // Get URL parameters. $systemcontext = context_system::instance(); $contextid = optional_param('context', $systemcontext->id, PARAM_INT); // Check permissions. list($context, $course, $cm) = get_context_info_array($contextid); require_login($course, false, $cm); require_capability('moodle/role:manage', $context); // Print the header. admin_externalpage_setup('toolcapability'); // Prepare the list of capabilities to choose from. $capabilitychoices = array(); foreach ($context->get_capabilities() as $cap) { $capabilitychoices[$cap->name] = $cap->name . ': ' . get_capability_string($cap->name); } $allroles = role_fix_names(get_all_roles($context)); // Prepare the list of roles to choose from. $rolechoices = array('0' => get_string('all')); foreach ($allroles as $role) { $rolechoices[$role->id] = $role->localname; } $form = new tool_capability_settings_form(null, array('capabilities' => $capabilitychoices, 'roles' => $rolechoices)); $PAGE->requires->yui_module('moodle-tool_capability-search', 'M.tool_capability.init_capability_search', array(array('strsearch' => get_string('search')))); // Log. $capabilities = array(); $rolestoshow = array(); $roleids = array('0'); $cleanedroleids = array(); if ($data = $form->get_data()) {
} } // Put the role capabilites into the context tree. if (!empty($rolecaps)) { foreach ($rolecaps as $rolecap) { $contexts[$rolecap->contextid]->rolecapabilites[$rolecap->roleid] = $rolecap->permission; } } // Fill in any missing rolecaps for the system context. foreach ($cleanedroleids as $roleid) { if (!isset($contexts[$systemcontext->id]->rolecapabilites[$roleid])) { $contexts[$systemcontext->id]->rolecapabilites[$roleid] = CAP_INHERIT; } } // Print the report heading. print_heading(get_string('reportforcapability', 'report_capability', get_capability_string($capability)), '', 2, 'main', false, 'report'); if (count($cleanedroleids) != count($allroles)) { $rolenames = array(); foreach ($cleanedroleids as $roleid) { $rolenames[] = $allroles[$roleid]->name; } echo '<p>', get_string('forroles', 'report_capability', implode(', ', $rolenames)), '</p>'; } // Now, recursively print the contexts, and the role information. print_report_tree($systemcontext->id, $contexts, $allroles); } // Footer. admin_externalpage_print_footer(); function print_report_tree($contextid, $contexts, $allroles) { global $CFG;
if ($parentcontextid) { $contexts[$parentcontextid]->children[] = $conid; } } // Put the role capabilities into the context tree. foreach ($rolecaps as $rolecap) { $contexts[$rolecap->contextid]->rolecapabilities[$rolecap->roleid] = $rolecap->permission; } // Fill in any missing rolecaps for the system context. foreach ($cleanedroleids as $roleid) { if (!isset($contexts[$systemcontext->id]->rolecapabilities[$roleid])) { $contexts[$systemcontext->id]->rolecapabilities[$roleid] = CAP_INHERIT; } } // Print the report heading. echo $OUTPUT->heading(get_string('reportforcapability', 'report_capability', get_capability_string($capability)), 2, 'main', 'report'); if (count($cleanedroleids) != count($allroles)) { $rolenames = array(); foreach ($cleanedroleids as $roleid) { $rolenames[] = $allroles[$roleid]->name; } echo '<p>', get_string('forroles', 'report_capability', implode(', ', $rolenames)), '</p>'; } // Now, recursively print the contexts, and the role information. print_report_tree($systemcontext->id, $contexts, $allroles); } // Footer. echo $OUTPUT->footer(); function print_report_tree($contextid, $contexts, $allroles) { global $CFG;
$declines = array(); // If a user can take attendance, they can approve staff's booking requests. if ($cantakeattendance) { $requests = facetoface_get_requests($session->id); } // If requests found (but not in the middle of taking attendance), show requests table. if ($requests && !$takeattendance) { $canapproverequests = true; } // Check the user is allowed to view this page. if (!$canviewattendees && !$cantakeattendance && !$canapproverequests && !$canviewcancellations) { print_error('nopermissions', '', "{$CFG->wwwroot}/mod/facetoface/view.php?id={$cm->id}", get_string('view')); } // Check user has permissions to take attendance. if ($takeattendance && !$cantakeattendance) { print_error('nopermissions', '', '', get_capability_string('mod/facetoface:takeattendance')); } /* * Handle submitted data */ if ($form = data_submitted()) { if (!confirm_sesskey()) { print_error('confirmsesskeybad', 'error'); } $return = "{$CFG->wwwroot}/mod/facetoface/attendees.php?s={$s}&backtoallsessions={$backtoallsessions}"; if ($cancelform) { redirect($return); } else { if (!empty($form->requests)) { // Approve requests. if ($canapproverequests && facetoface_approve_requests($form)) {
// $Id: exportgood.php,v 1.4 2008/12/02 09:49:53 jamiesensei Exp $ /** * Export questions in the given category and which have been assigned a grade * above a certain level. * * @author Martin Dougiamas, Howard Miller, Jamie Pratt and many others. * {@link http://moodle.org} * @license http://www.gnu.org/copyleft/gpl.html GNU Public License */ require_once "../../config.php"; require_once $CFG->dirroot . "/question/editlib.php"; require_once "export_good_questions_form.php"; list($thispageurl, $contexts, $cmid, $cm, $qcreate, $pagevars) = question_edit_setup('export', true); if (!has_capability('moodle/question:viewmine', $contexts->lowest()) && !has_capability('moodle/question:viewall', $contexts->lowest())) { $capabilityname = get_capability_string('moodle/question:viewmine'); print_error('nopermissions', '', '', $capabilityname); } // get display strings $txt = new object(); $txt->category = get_string('category', 'quiz'); $txt->download = get_string('download', 'quiz'); $txt->downloadextra = get_string('downloadextra', 'quiz'); $txt->exporterror = get_string('exporterror', 'quiz'); $txt->exportname = get_string('exportname', 'quiz'); $txt->exportquestions = get_string('exportquestions', 'quiz'); $txt->fileformat = get_string('fileformat', 'quiz'); $txt->exportcategory = get_string('exportcategory', 'quiz'); $txt->modulename = get_string('modulename', 'quiz'); $txt->modulenameplural = get_string('modulenameplural', 'quiz'); $txt->tofile = get_string('tofile', 'quiz');
function get_cap_string($capability) { global $CFG; $doc_ref = 'http://docs.moodle.org/' . $CFG->lang . '/Capabilities/' . $capability['name']; return "<td class=\"action\">\n <span class=\"cap_friendly_name\"><a href=\"{$doc_ref}\">" . get_capability_string($capability['name']) . "</a></span>\n <span class=\"cap_name\">{$capability['name']}</span>" . get_risks_images($capability) . '</td>'; }
/** * Add additional attributes to row * * @param stdClass $capability capability that this table row relates to. * @return array key value pairs of attribute names and values. */ protected function get_row_attributes($capability) { return array('data-id' => $capability->id, 'data-name' => $capability->name, 'data-humanname' => get_capability_string($capability->name)); }
/** * This is an easy to use function, combining has_capability() with require_course_login(). * And will call those where needed. * * It checks for a capability assertion being true. If it isn't * then the page is terminated neatly with a standard error message. * * If the user is not logged in, or is using 'guest' access or other special "users, * it provides a logon prompt. * * @param string $capability - name of the capability * @param object $context - a context object (record from context table) * @param integer $userid - a userid number * @param bool $doanything - if false, ignore do anything * @param string $errorstring - an errorstring * @param string $stringfile - which stringfile to get it from */ function require_capability($capability, $context = NULL, $userid = NULL, $doanything = true, $errormessage = 'nopermissions', $stringfile = '') { global $USER, $CFG; /// If the current user is not logged in, then make sure they are (if needed) if (is_null($userid) && !isset($USER->access)) { if ($context && $context->contextlevel == CONTEXT_COURSE) { require_login($context->instanceid); } else { if ($context && $context->contextlevel == CONTEXT_MODULE) { if ($cm = get_record('course_modules', 'id', $context->instanceid)) { if (!($course = get_record('course', 'id', $cm->course))) { error('Incorrect course.'); } require_course_login($course, true, $cm); } else { require_login(); } } else { if ($context && $context->contextlevel == CONTEXT_SYSTEM) { if (!empty($CFG->forcelogin)) { require_login(); } } else { require_login(); } } } } /// OK, if they still don't have the capability then print a nice error message if (!has_capability($capability, $context, $userid, $doanything)) { $capabilityname = get_capability_string($capability); print_error($errormessage, $stringfile, '', $capabilityname); } }
/** * Constructor * @param context $context The context used for the capability check * @param string $capability The required capability * @param string $errormessage The error message to show the user * @param string $stringfile */ function __construct($context, $capability, $errormessage, $stringfile) { $capabilityname = get_capability_string($capability); if ($context->contextlevel == CONTEXT_MODULE and preg_match('/:view$/', $capability)) { // we can not go to mod/xx/view.php because we most probably do not have cap to view it, let's go to course instead $paranetcontext = context::instance_by_id(get_parent_contextid($context)); $link = get_context_url($paranetcontext); } else { $link = get_context_url($context); } parent::__construct($errormessage, $stringfile, $link, $capabilityname); }
function html_header($course, $wdir, $formfield = "") { global $CFG, $ME, $USER, $id, $shared, $userid, $oid, $uuid, $repo, $canedit; /// Get the appropriate context for the site, course or organization. if (!empty($oid)) { $cluster_context = get_context_instance(context_level_base::get_custom_context_level('cluster', 'block_curr_admin'), $oid); } if ($id == SITEID) { $context = get_context_instance(CONTEXT_SYSTEM, SITEID); } else { $context = get_context_instance(CONTEXT_COURSE, $id); } /// Make sure that we have the correct 'base' UUID for a course or user storage area as well /// as checking for correct permissions. if (!empty($userid) && !empty($id)) { $personalfiles = false; if (!empty($USER->access['rdef'])) { foreach ($USER->access['rdef'] as $ucontext) { if ($personalfiles) { continue; } if (isset($ucontext['block/repository:viewowncontent']) && $ucontext['block/repository:viewowncontent'] == CAP_ALLOW) { $personalfiles = true; } } } if (!$personalfiles) { $capabilityname = get_capability_string('block/repository:viewowncontent'); print_error('nopermissions', '', '', $capabilityname); exit; } if (empty($uuid)) { $uuid = $repo->get_user_store($userid); } } else { if (empty($userid) && !empty($shared)) { $sharedfiles = false; if (!empty($USER->access['rdef'])) { foreach ($USER->access['rdef'] as $ucontext) { if ($sharedfiles) { continue; } if (isset($ucontext['block/repository:viewsharedcontent']) && $ucontext['block/repository:viewsharedcontent'] == CAP_ALLOW) { $sharedfiles = true; } } } if (!$sharedfiles) { $capabilityname = get_capability_string('block/repository:viewsharedcontent'); print_error('nopermissions', '', '', $capabilityname); exit; } if (empty($uuid)) { $uuid = $repo->suuid; } } else { if (!empty($id) && empty($oid) && $id != SITEID) { require_capability('block/repository:viewcoursecontent', $context, $USER->id); if (empty($uuid)) { $uuid = $repo->get_course_store($id); } } else { if (!empty($oid)) { require_capability('block/repository:vieworganizationcontent', $cluster_context, $USER->id); if (empty($uuid)) { $uuid = $repo->get_organization_store($oid); } } else { require_capability('block/repository:viewsitecontent', $context, $USER->id); if (empty($uuid)) { if ($root = $repo->get_root()) { $uuid = $root->uuid; } } } } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>coursefiles</title> <script type="text/javascript"> //<![CDATA[ function set_value(params) { /// function's argument is an object containing necessary values /// to export parent window (url,isize,itype,iwidth,iheight, imodified) /// set values when user click's an image name. var upper = window.parent; var insimg = upper.document.getElementById('f_url'); try { if(insimg != null) { if(params.itype.indexOf("image/gif") == -1 && params.itype.indexOf("image/jpeg") == -1 && params.itype.indexOf("image/png") == -1) { alert("<?php print_string("notimage", "editor"); ?> "); return false; } for(field in params) { var value = params[field]; switch(field) { case "url" : upper.document.getElementById('f_url').value = value; upper.ipreview.location.replace('<?php echo $CFG->wwwroot; ?> /lib/editor/htmlarea/popups/preview.php?id='+ <?php print $course->id; ?> +'&imageurl='+ value); break; case "isize" : upper.document.getElementById('isize').value = value; break; case "itype" : upper.document.getElementById('itype').value = value; break; case "iwidth": upper.document.getElementById('f_width').value = value; break; case "iheight": upper.document.getElementById('f_height').value = value; break; } } } else { for(field in params) { var value = params[field]; switch(field) { case "url" : //upper.document.getElementById('f_href').value = value; upper.opener.document.getElementById('f_href').value = value; upper.close(); break; //case "imodified" : upper.document.getElementById('imodified').value = value; break; //case "isize" : upper.document.getElementById('isize').value = value; break; //case "itype" : upper.document.getElementById('itype').value = value; break; } } } } catch(e) { if ( window.tinyMCE != "undefined" || window.TinyMCE != "undefined" ) { upper.opener.Dialog._return(params.url); upper.close(); } else { alert("Something odd just occurred!!!"); } } return false; } function set_dir(strdir) { // sets wdir values var upper = window.parent.document; if(upper) { for(var i = 0; i < upper.forms.length; i++) { var f = upper.forms[i]; if(f.wdir != undefined) { //TODO: this needs to be replaced since it never seems to be used try { f.wdir.value = strdir; } catch (e) { } } } } } function set_rename(strfile) { var upper = window.parent.document; //ERROR: element irename does not exist needs to be replaced with proper element // upper.getElementById('irename').value = strfile; //this or next line // upper.getElementById('irename').file.value = strfile; return true; } function reset_value() { var upper = window.parent.document; for(var i = 0; i < upper.forms.length; i++) { var f = upper.forms[i]; for(var j = 0; j < f.elements.length; j++) { var e = f.elements[j]; // Do not reset submit, button, hidden, or select-one types if(e.type != "submit" && e.type != "button" && e.type != "hidden" && e.type != "select-one") { try { e.value = ""; } catch (e) { } } } } //ERROR: there is no element irename this needs to be replaced with the proper element // upper.getElementById('irename').value = 'xx'; var prev = window.parent.ipreview; if(prev != null) { prev.location.replace('about:blank'); } var uploader = window.parent.document.forms['uploader']; if(uploader != null) { uploader.reset(); } set_dir('<?php print $wdir; ?> '); return true; } //]]> </script> <style type="text/css"> body { background-color: white; margin-top: 2px; margin-left: 4px; margin-right: 4px; } body,p,table,td,input,select,a { font-family: Tahoma, sans-serif; font-size: 11px; } select { position: absolute; top: -20px; left: 0px; } img.icon { vertical-align:middle; margin-right:4px; width:16px; height:16px; border:0px; } </style> </head> <body onload="reset_value();"> <?php }
/** * Return a link to moodle docs for a given capability name * * @param object $capability a capability - a row from the mdl_capabilities table. * @return string the human-readable capability name as a link to Moodle Docs. */ function get_capability_docs_link($capability) { $url = get_docs_url('Capabilities/' . $capability->name); return '<a onclick="this.target=\'docspopup\'" href="' . $url . '">' . get_capability_string($capability->name) . '</a>'; }
/** * Process the role comparison. * @throws Commmand_Exception. */ private function _process() { global $CFG, $DB, $OUTPUT; // Checking if command has been runned. if (!$this->isRunned()) { throw new Command_Exception('commandnotrun'); } // Defining capabilities values. $cap_permissions = array(CAP_ALLOW => array('count' => 0, 'label' => 1, 'name' => 'allow'), CAP_PREVENT => array('count' => 0, 'label' => 2, 'name' => 'prevent'), CAP_PROHIBIT => array('count' => 0, 'label' => 3, 'name' => 'prohibit')); // Defining capabilities context. $cap_contexts = array(CONTEXT_BLOCK => array('count' => 0, 'label' => 'B', 'name' => 'block'), CONTEXT_COURSE => array('count' => 0, 'label' => 'C', 'name' => 'course'), CONTEXT_COURSECAT => array('count' => 0, 'label' => 'CC', 'name' => 'coursecat'), CONTEXT_MODULE => array('count' => 0, 'label' => 'M', 'name' => 'module'), CONTEXT_SYSTEM => array('count' => 0, 'label' => 'S', 'name' => 'system'), CONTEXT_USER => array('count' => 0, 'label' => 'U', 'name' => 'user')); // Getting role name. $role = $this->getParameter('role')->getValue(); $role = $DB->get_record('role', array('shortname' => $role)); // Getting hosts. $hosts = array_keys($this->capabilities); $host_labels = get_available_platforms(); // Getting capabilities. $records_capabilities = $DB->get_records('capabilities', null, '', 'name,contextlevel,component'); // Getting lang. $lang = str_replace('_utf8', '', current_language()); $strcapabilities = s(get_string('capabilities', 'role')); // 'Capabilities' MDL-11687 // Getting all capabilities names. $capability_names = array(); foreach ($this->capabilities as $platform_capabilities) { $platform_capabilities = array_keys((array) $platform_capabilities); $capability_names = array_merge($capability_names, $platform_capabilities); } $capability_names = array_unique($capability_names); // Getting problematic component name $problematic_component_name = get_string('problematiccomponent', 'vmoodleadminset_roles'); // Creating normalized capabilities. $capabilities = array(); foreach ($capability_names as $capability_name) { // Creating capability. $capability = new \StdClass(); $capability->name = $capability_name; // Initializing counters. $cap_permissions[CAP_ALLOW]['count'] = $cap_permissions[CAP_PREVENT]['count'] = $cap_permissions[CAP_PROHIBIT]['count'] = 0; $cap_contexts[CONTEXT_BLOCK]['count'] = $cap_contexts[CONTEXT_COURSE]['count'] = $cap_contexts[CONTEXT_COURSECAT]['count'] = $cap_contexts[CONTEXT_MODULE]['count'] = $cap_contexts[CONTEXT_SYSTEM]['count'] = $cap_contexts[CONTEXT_USER]['count'] = 0; // Counting. foreach ($this->capabilities as $platform_capabilities) { if (!property_exists($platform_capabilities, $capability_name) || is_null($platform_capabilities->{$capability_name})) { continue; } $platform_capability = $platform_capabilities->{$capability_name}; $cap_permissions[$platform_capability->permission]['count']++; $cap_contexts[$platform_capability->contextlevel]['count']++; } // Getting major values. $nbr_value_max = max(array_map(array($this, '_getCounterValue'), $cap_permissions)); $nbr_context_max = max(array_map(array($this, '_getCounterValue'), $cap_contexts)); // Setting major permission. foreach ($cap_permissions as $permission => $cap_permission) { if ($cap_permission['count'] == $nbr_value_max) { $capability->major_permission = $permission; break; } } // Setting major contexlevel. foreach ($cap_contexts as $contextlevel => $cap_context) { if ($cap_context['count'] == $nbr_context_max) { $capability->major_contextlevel = $contextlevel; break; } } // Setting component. $capability->component = isset($records_capabilities[$capability_name]) ? $records_capabilities[$capability_name]->component : $problematic_component_name; // Setting capability contextlevel. $capability->contextlevel = isset($records_capabilities[$capability_name]) ? $records_capabilities[$capability_name]->contextlevel : CONTEXT_SYSTEM; // Adding capability. $capabilities[$capability_name] = $capability; } // Sort capabilities on contextlevel, component and name. uasort($capabilities, array($this, '_orderCapability')); /* * Creating html report. */ // Creating header. $this->report = '<h3>' . get_string('comparerole', 'vmoodleadminset_roles', $role->name) . help_button_vml('rolelib', 'rolecompare', 'rolecompare') . '</h3>'; // Adding edit role link. $this->report .= '<center><p>' . $OUTPUT->single_button(new moodle_url('/admin/roles/define.php', array('roleid' => $role->id, 'action' => 'edit')), get_string('editrole', 'vmoodleadminset_roles'), 'get') . '</p></center>'; // Adding a capability client side filter. $this->report .= get_string('capfilter', 'local_vmoodle') . ': ' . '<input type="text" name="capfilter" value="" onchange="filtercapabilitytable(this)" />'; // Creation form. $rolecapsyncurl = new moodle_url('/local/vmoodle/plugins/roles/controller.rolelib.sadmin.php', array('what' => 'syncrole')); $this->report .= '<form action="' . $rolecapsyncurl . '" method="post" onsubmit="return validate_syncrole()">'; $this->report .= '<input id="capability" type="hidden" name="capability" value="" />'; $this->report .= '<input id="source_platform" type="hidden" name="source_platform" value="" />'; // Creating table. $this->report .= '<table id="rolecompare" cellspacing="1" cellpadding="5" class="generaltable boxaligncenter" style="min-width: 75%;"><tbody>'; // Creating header. $this->report .= '<tr><th scope="col" class="header c0" style="vertical-align: bottom; text-align: left;"> </th>'; $col = 1; foreach ($hosts as $host) { $this->report .= '<th id="cap_' . $col . '" scope="col" class="header c' . $col . '" style="vertical-align: bottom; text-align: center;"><label for="platform_' . $col . '"><img src="' . $CFG->wwwroot . '/local/vmoodle/plugins/roles/draw_platformname.php?caption=' . urlencode($host_labels[$host]) . '" alt="' . $host_labels[$host] . '"/></label><br/><input id="platform_' . $col . '" type="checkbox" name="platforms[]" value="' . $host . '" disabled="disabled"/></th>'; $col++; } $this->report .= '</tr>'; // Initializing variables. $row = 0; $contextlevel = 0; $component = ''; $rowtitleids = array(); // Creating table data. foreach ($capabilities as $capability) { $col = 1; $componentlevelchanged = component_level_changed($capability, $component, $contextlevel); // Recording context. $contextlevel = $capability->contextlevel; $component = $capability->component; $rowtitleids[] = $capability->name; $rowcontent = '<tr class="r' . $row % 2 . ' capabilityrow" id="' . $capability->name . '">'; $rowcontent .= '<td id="cap_0_' . $row . '" class="cell c0" style="vertical-align: middle; text-align: left;"><a onclick="this.target=\'docspopup\'" href="' . $CFG->docroot . '/' . $lang . '/' . $strcapabilities . '/' . $capability->name . '">' . get_capability_string($capability->name) . '</a><br/>' . $capability->name . '</td>'; foreach ($hosts as $host) { $extra_class = false; $title = get_capability_string($capability->name) . ' | ' . $host_labels[$host]; if (array_key_exists($host, $this->capabilities) && property_exists($this->capabilities[$host], $capability->name)) { $platform_capability = $this->capabilities[$host]->{$capability->name}; if (is_null($platform_capability)) { $cell = '<img src="' . $CFG->wwwroot . '/local/vmoodle/plugins/roles/pix/norolecapability.png" alt="No role capability" title="' . $title . '" onclick="setCapability(' . $col . ',' . $row . ',\'' . $capability->name . '\',\'' . $host . '\');"/>'; } else { $cell = '<img src="' . $CFG->wwwroot . '/local/vmoodle/plugins/roles/pix/compare' . $cap_permissions[$platform_capability->permission]['label'] . $cap_contexts[$platform_capability->contextlevel]['label'] . '.png" alt="Permission: ' . $cap_permissions[$platform_capability->permission]['name'] . ' | Context: ' . $cap_contexts[$platform_capability->contextlevel]['name'] . '" title="' . $title . '" onclick="setCapability(' . $col . ',' . $row . ',\'' . $capability->name . '\',\'' . $host . '\');"/>'; if ($platform_capability->permission != $capabilities[$platform_capability->capability]->major_permission) { $extra_class = 'wrongvalue'; } elseif ($platform_capability->contextlevel != $capabilities[$platform_capability->capability]->major_contextlevel) { $extra_class = 'wrongcontext'; } } } else { $cell = '<img src="' . $CFG->wwwroot . '/local/vmoodle/plugins/roles/pix/nocapability.png" alt="No capability" title="' . $title . '"/>'; } $rowcontent .= '<td id="cap_' . $col . '_' . $row . '" class="cell c' . $col . ($extra_class ? ' ' . $extra_class : '') . '" style="vertical-align: middle; text-align: center;" onmouseout="cellOut(' . $col . ',' . $row . ');" onmouseover="cellOver(' . $col . ',' . $row . ');">' . $cell . '</td>'; $col++; } // Adding contextual heading. if ($componentlevelchanged) { $rowhead = '<tr class="capabilityrow" id="' . implode(',', $rowtitleids) . '"><td colspan="' . (count($hosts) + 1) . '" class="header"><strong>' . ($capability->component == $problematic_component_name ? $problematic_component_name : get_component_string($capability->component, $capability->contextlevel)) . '</strong></td></tr>'; $rowtitleids = array(); } $this->report .= $rowhead . $rowcontent . '</tr>'; $row++; } // Closing table. $this->report .= '</tboby></table><br/><center><input type="submit" value="' . get_string('synchronize', 'vmoodleadminset_roles') . '"/><div id="rolecompare_validation_message"></div></center></form><br/><br/>'; }