[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/tool/capability/ -> index.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * For a given capability, show what permission it has for every role, and everywhere that it is overridden.
  19   *
  20   * @package    tool_capability
  21   * @copyright  2008 Tim Hunt
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once(__DIR__ . '/../../../config.php');
  26  require_once($CFG->dirroot.'/'.$CFG->admin.'/tool/capability/locallib.php');
  27  require_once($CFG->libdir.'/adminlib.php');
  28  
  29  // Get URL parameters.
  30  $systemcontext = context_system::instance();
  31  $contextid = optional_param('context', $systemcontext->id, PARAM_INT);
  32  
  33  // Check permissions.
  34  list($context, $course, $cm) = get_context_info_array($contextid);
  35  require_login($course, false, $cm);
  36  require_capability('moodle/role:manage', $context);
  37  
  38  // Print the header.
  39  admin_externalpage_setup('toolcapability');
  40  
  41  // Prepare the list of capabilities to choose from.
  42  $capabilitychoices = array();
  43  foreach ($context->get_capabilities() as $cap) {
  44      $capabilitychoices[$cap->name] = $cap->name . ': ' . get_capability_string($cap->name);
  45  }
  46  
  47  $allroles = role_fix_names(get_all_roles($context));
  48  // Prepare the list of roles to choose from.
  49  $rolechoices = array('0' => get_string('all'));
  50  foreach ($allroles as $role) {
  51      $rolechoices[$role->id] = $role->localname;
  52  }
  53  
  54  $form = new tool_capability_settings_form(null, array(
  55      'capabilities' => $capabilitychoices,
  56      'roles' => $rolechoices
  57  ));
  58  $PAGE->requires->yui_module(
  59      'moodle-tool_capability-search',
  60      'M.tool_capability.init_capability_search',
  61      array(array('strsearch' => get_string('search')))
  62  );
  63  
  64  // Log.
  65  $capabilities = array();
  66  $rolestoshow = array();
  67  $roleids = array('0');
  68  $cleanedroleids = array();
  69  if ($data = $form->get_data()) {
  70  
  71      $roleids = array();
  72      if (!empty($data->roles)) {
  73          $roleids = $data->roles;
  74      }
  75  
  76      $capabilities = array();
  77      if (!empty($data->capability)) {
  78          $capabilities = $data->capability;
  79      }
  80  
  81      if (in_array('0', $roleids)) {
  82          $rolestoshow = $allroles;
  83      } else {
  84          $cleanedroleids = array_intersect(array_keys($allroles), $roleids);
  85          if (count($cleanedroleids) === 0) {
  86              $rolestoshow = $allroles;
  87          } else {
  88              foreach ($cleanedroleids as $id) {
  89                  $rolestoshow[$id] = $allroles[$id];
  90              }
  91          }
  92      }
  93  }
  94  
  95  \tool_capability\event\report_viewed::create()->trigger();
  96  
  97  $renderer = $PAGE->get_renderer('tool_capability');
  98  
  99  echo $OUTPUT->header();
 100  
 101  $form->display();
 102  
 103  // If we have a capability, generate the report.
 104  if (count($capabilities) && count($rolestoshow)) {
 105      /* @var tool_capability_renderer $renderer */
 106      echo $renderer->capability_comparison_table($capabilities, $context->id, $rolestoshow);
 107  }
 108  
 109  // Footer.
 110  echo $OUTPUT->footer();
 111  
 112  function print_report_tree($contextid, $contexts, $allroles) {
 113      global $CFG;
 114  
 115      // Array for holding lang strings.
 116      static $strpermissions = null;
 117      if (is_null($strpermissions)) {
 118          $strpermissions = array(
 119              CAP_INHERIT => get_string('notset','role'),
 120              CAP_ALLOW => get_string('allow','role'),
 121              CAP_PREVENT => get_string('prevent','role'),
 122              CAP_PROHIBIT => get_string('prohibit','role')
 123          );
 124      }
 125  
 126      // Start the list item, and print the context name as a link to the place to
 127      // make changes.
 128      if ($contextid == context_system::instance()->id) {
 129          $url = "$CFG->wwwroot/$CFG->admin/roles/manage.php";
 130          $title = get_string('changeroles', 'tool_capability');
 131      } else {
 132          $url = "$CFG->wwwroot/$CFG->admin/roles/override.php?contextid=$contextid";
 133          $title = get_string('changeoverrides', 'tool_capability');
 134      }
 135      $context = context::instance_by_id($contextid);
 136      echo '<h3><a href="' . $url . '" title="' . $title . '">', $context->get_context_name(), '</a></h3>';
 137  
 138      // If there are any role overrides here, print them.
 139      if (!empty($contexts[$contextid]->rolecapabilities)) {
 140          $rowcounter = 0;
 141          echo '<table class="generaltable rolecaps"><tbody>';
 142          foreach ($allroles as $role) {
 143              if (isset($contexts[$contextid]->rolecapabilities[$role->id])) {
 144                  $permission = $contexts[$contextid]->rolecapabilities[$role->id];
 145                  echo '<tr class="r' . ($rowcounter % 2) . '"><th class="cell">', $role->localname,
 146                          '</th><td class="cell">' . $strpermissions[$permission] . '</td></tr>';
 147                  $rowcounter++;
 148              }
 149          }
 150          echo '</tbody></table>';
 151      }
 152  
 153      // After we have done the site context, change the string for CAP_INHERIT
 154      // from 'notset' to 'inherit'.
 155      $strpermissions[CAP_INHERIT] = get_string('inherit','role');
 156  
 157      // If there are any child contexts, print them recursively.
 158      if (!empty($contexts[$contextid]->children)) {
 159          echo '<ul>';
 160          foreach ($contexts[$contextid]->children as $childcontextid) {
 161              echo '<li>';
 162              print_report_tree($childcontextid, $contexts, $allroles);
 163              echo '</li>';
 164          }
 165          echo '</ul>';
 166      }
 167  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1