[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/libraries/joomla/form/fields/ -> rules.php (source)

   1  <?php
   2  /**
   3   * @package     Joomla.Platform
   4   * @subpackage  Form
   5   *
   6   * @copyright   Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   7   * @license     GNU General Public License version 2 or later; see LICENSE
   8   */
   9  
  10  defined('JPATH_PLATFORM') or die;
  11  
  12  /**
  13   * Form Field class for the Joomla Platform.
  14   * Field for assigning permissions to groups for a given asset
  15   *
  16   * @package     Joomla.Platform
  17   * @subpackage  Form
  18   * @see         JAccess
  19   * @since       11.1
  20   */
  21  class JFormFieldRules extends JFormField
  22  {
  23      /**
  24       * The form field type.
  25       *
  26       * @var    string
  27       * @since  11.1
  28       */
  29      public $type = 'Rules';
  30  
  31      /**
  32       * Method to get the field input markup for Access Control Lists.
  33       * Optionally can be associated with a specific component and section.
  34       *
  35       * TODO: Add access check.
  36       *
  37       * @return  string  The field input markup.
  38       *
  39       * @since   11.1
  40       */
  41  	protected function getInput()
  42      {
  43          JHtml::_('behavior.tooltip');
  44  
  45          // Initialise some field attributes.
  46          $section = $this->element['section'] ? (string) $this->element['section'] : '';
  47          $component = $this->element['component'] ? (string) $this->element['component'] : '';
  48          $assetField = $this->element['asset_field'] ? (string) $this->element['asset_field'] : 'asset_id';
  49  
  50          // Get the actions for the asset.
  51          $actions = JAccess::getActions($component, $section);
  52  
  53          // Iterate over the children and add to the actions.
  54          foreach ($this->element->children() as $el)
  55          {
  56              if ($el->getName() == 'action')
  57              {
  58                  $actions[] = (object) array('name' => (string) $el['name'], 'title' => (string) $el['title'],
  59                      'description' => (string) $el['description']);
  60              }
  61          }
  62  
  63          // Get the explicit rules for this asset.
  64          if ($section == 'component')
  65          {
  66              // Need to find the asset id by the name of the component.
  67              $db = JFactory::getDbo();
  68              $query = $db->getQuery(true);
  69              $query->select($db->quoteName('id'));
  70              $query->from($db->quoteName('#__assets'));
  71              $query->where($db->quoteName('name') . ' = ' . $db->quote($component));
  72              $db->setQuery($query);
  73              $assetId = (int) $db->loadResult();
  74  
  75              if ($error = $db->getErrorMsg())
  76              {
  77                  JError::raiseNotice(500, $error);
  78              }
  79          }
  80          else
  81          {
  82              // Find the asset id of the content.
  83              // Note that for global configuration, com_config injects asset_id = 1 into the form.
  84              $assetId = $this->form->getValue($assetField);
  85          }
  86  
  87          // Use the compact form for the content rules (deprecated).
  88          //if (!empty($component) && $section != 'component') {
  89          //    return JHtml::_('rules.assetFormWidget', $actions, $assetId, $assetId ? null : $component, $this->name, $this->id);
  90          //}
  91  
  92          // Full width format.
  93  
  94          // Get the rules for just this asset (non-recursive).
  95          $assetRules = JAccess::getAssetRules($assetId);
  96  
  97          // Get the available user groups.
  98          $groups = $this->getUserGroups();
  99  
 100          // Build the form control.
 101          $curLevel = 0;
 102  
 103          // Prepare output
 104          $html = array();
 105          $html[] = '<div id="permissions-sliders" class="pane-sliders">';
 106          $html[] = '<p class="rule-desc">' . JText::_('JLIB_RULES_SETTINGS_DESC') . '</p>';
 107          $html[] = '<ul id="rules">';
 108  
 109          // Start a row for each user group.
 110          foreach ($groups as $group)
 111          {
 112              $difLevel = $group->level - $curLevel;
 113  
 114              if ($difLevel > 0)
 115              {
 116                  $html[] = '<li><ul>';
 117              }
 118              elseif ($difLevel < 0)
 119              {
 120                  $html[] = str_repeat('</ul></li>', -$difLevel);
 121              }
 122  
 123              $html[] = '<li>';
 124  
 125              $html[] = '<div class="panel">';
 126              $html[] = '<h3 class="pane-toggler title"><a href="javascript:void(0);"><span>';
 127              $html[] = str_repeat('<span class="level">|&ndash;</span> ', $curLevel = $group->level) . $group->text;
 128              $html[] = '</span></a></h3>';
 129              $html[] = '<div class="pane-slider content pane-hide">';
 130              $html[] = '<div class="mypanel">';
 131              $html[] = '<table class="group-rules">';
 132              $html[] = '<thead>';
 133              $html[] = '<tr>';
 134  
 135              $html[] = '<th class="actions" id="actions-th' . $group->value . '">';
 136              $html[] = '<span class="acl-action">' . JText::_('JLIB_RULES_ACTION') . '</span>';
 137              $html[] = '</th>';
 138  
 139              $html[] = '<th class="settings" id="settings-th' . $group->value . '">';
 140              $html[] = '<span class="acl-action">' . JText::_('JLIB_RULES_SELECT_SETTING') . '</span>';
 141              $html[] = '</th>';
 142  
 143              // The calculated setting is not shown for the root group of global configuration.
 144              $canCalculateSettings = ($group->parent_id || !empty($component));
 145              if ($canCalculateSettings)
 146              {
 147                  $html[] = '<th id="aclactionth' . $group->value . '">';
 148                  $html[] = '<span class="acl-action">' . JText::_('JLIB_RULES_CALCULATED_SETTING') . '</span>';
 149                  $html[] = '</th>';
 150              }
 151  
 152              $html[] = '</tr>';
 153              $html[] = '</thead>';
 154              $html[] = '<tbody>';
 155  
 156              foreach ($actions as $action)
 157              {
 158                  $html[] = '<tr>';
 159                  $html[] = '<td headers="actions-th' . $group->value . '">';
 160                  $html[] = '<label class="hasTip" for="' . $this->id . '_' . $action->name . '_' . $group->value . '" title="'
 161                      . htmlspecialchars(JText::_($action->title) . '::' . JText::_($action->description), ENT_COMPAT, 'UTF-8') . '">';
 162                  $html[] = JText::_($action->title);
 163                  $html[] = '</label>';
 164                  $html[] = '</td>';
 165  
 166                  $html[] = '<td headers="settings-th' . $group->value . '">';
 167  
 168                  $html[] = '<select name="' . $this->name . '[' . $action->name . '][' . $group->value . ']" id="' . $this->id . '_' . $action->name
 169                      . '_' . $group->value . '" title="'
 170                      . JText::sprintf('JLIB_RULES_SELECT_ALLOW_DENY_GROUP', JText::_($action->title), trim($group->text)) . '">';
 171  
 172                  $inheritedRule = JAccess::checkGroup($group->value, $action->name, $assetId);
 173  
 174                  // Get the actual setting for the action for this group.
 175                  $assetRule = $assetRules->allow($action->name, $group->value);
 176  
 177                  // Build the dropdowns for the permissions sliders
 178  
 179                  // The parent group has "Not Set", all children can rightly "Inherit" from that.
 180                  $html[] = '<option value=""' . ($assetRule === null ? ' selected="selected"' : '') . '>'
 181                      . JText::_(empty($group->parent_id) && empty($component) ? 'JLIB_RULES_NOT_SET' : 'JLIB_RULES_INHERITED') . '</option>';
 182                  $html[] = '<option value="1"' . ($assetRule === true ? ' selected="selected"' : '') . '>' . JText::_('JLIB_RULES_ALLOWED')
 183                      . '</option>';
 184                  $html[] = '<option value="0"' . ($assetRule === false ? ' selected="selected"' : '') . '>' . JText::_('JLIB_RULES_DENIED')
 185                      . '</option>';
 186  
 187                  $html[] = '</select>&#160; ';
 188  
 189                  // If this asset's rule is allowed, but the inherited rule is deny, we have a conflict.
 190                  if (($assetRule === true) && ($inheritedRule === false))
 191                  {
 192                      $html[] = JText::_('JLIB_RULES_CONFLICT');
 193                  }
 194  
 195                  $html[] = '</td>';
 196  
 197                  // Build the Calculated Settings column.
 198                  // The inherited settings column is not displayed for the root group in global configuration.
 199                  if ($canCalculateSettings)
 200                  {
 201                      $html[] = '<td headers="aclactionth' . $group->value . '">';
 202  
 203                      // This is where we show the current effective settings considering currrent group, path and cascade.
 204                      // Check whether this is a component or global. Change the text slightly.
 205  
 206                      if (JAccess::checkGroup($group->value, 'core.admin') !== true)
 207                      {
 208                          if ($inheritedRule === null)
 209                          {
 210                              $html[] = '<span class="icon-16-unset">' . JText::_('JLIB_RULES_NOT_ALLOWED') . '</span>';
 211                          }
 212                          elseif ($inheritedRule === true)
 213                          {
 214                              $html[] = '<span class="icon-16-allowed">' . JText::_('JLIB_RULES_ALLOWED') . '</span>';
 215                          }
 216                          elseif ($inheritedRule === false)
 217                          {
 218                              if ($assetRule === false)
 219                              {
 220                                  $html[] = '<span class="icon-16-denied">' . JText::_('JLIB_RULES_NOT_ALLOWED') . '</span>';
 221                              }
 222                              else
 223                              {
 224                                  $html[] = '<span class="icon-16-denied"><span class="icon-16-locked">' . JText::_('JLIB_RULES_NOT_ALLOWED_LOCKED')
 225                                      . '</span></span>';
 226                              }
 227                          }
 228                      }
 229                      elseif (!empty($component))
 230                      {
 231                          $html[] = '<span class="icon-16-allowed"><span class="icon-16-locked">' . JText::_('JLIB_RULES_ALLOWED_ADMIN')
 232                              . '</span></span>';
 233                      }
 234                      else
 235                      {
 236                          // Special handling for  groups that have global admin because they can't  be denied.
 237                          // The admin rights can be changed.
 238                          if ($action->name === 'core.admin')
 239                          {
 240                              $html[] = '<span class="icon-16-allowed">' . JText::_('JLIB_RULES_ALLOWED') . '</span>';
 241                          }
 242                          elseif ($inheritedRule === false)
 243                          {
 244                              // Other actions cannot be changed.
 245                              $html[] = '<span class="icon-16-denied"><span class="icon-16-locked">'
 246                                  . JText::_('JLIB_RULES_NOT_ALLOWED_ADMIN_CONFLICT') . '</span></span>';
 247                          }
 248                          else
 249                          {
 250                              $html[] = '<span class="icon-16-allowed"><span class="icon-16-locked">' . JText::_('JLIB_RULES_ALLOWED_ADMIN')
 251                                  . '</span></span>';
 252                          }
 253                      }
 254  
 255                      $html[] = '</td>';
 256                  }
 257  
 258                  $html[] = '</tr>';
 259              }
 260  
 261              $html[] = '</tbody>';
 262              $html[] = '</table></div>';
 263  
 264              $html[] = '</div></div>';
 265              $html[] = '</li>';
 266  
 267          }
 268  
 269          $html[] = str_repeat('</ul></li>', $curLevel);
 270          $html[] = '</ul><div class="rule-notes">';
 271          if ($section == 'component' || $section == null)
 272          {
 273              $html[] = JText::_('JLIB_RULES_SETTING_NOTES');
 274          }
 275          else
 276          {
 277              $html[] = JText::_('JLIB_RULES_SETTING_NOTES_ITEM');
 278          }
 279          $html[] = '</div></div>';
 280  
 281          $js = "window.addEvent('domready', function(){ new Fx.Accordion($$('div#permissions-sliders.pane-sliders .panel h3.pane-toggler'),"
 282              . "$$('div#permissions-sliders.pane-sliders .panel div.pane-slider'), {onActive: function(toggler, i) {toggler.addClass('pane-toggler-down');"
 283              . "toggler.removeClass('pane-toggler');i.addClass('pane-down');i.removeClass('pane-hide');Cookie.write('jpanesliders_permissions-sliders"
 284              . $component
 285              . "',$$('div#permissions-sliders.pane-sliders .panel h3').indexOf(toggler));},"
 286              . "onBackground: function(toggler, i) {toggler.addClass('pane-toggler');toggler.removeClass('pane-toggler-down');i.addClass('pane-hide');"
 287              . "i.removeClass('pane-down');}, duration: 300, display: "
 288              . JRequest::getInt('jpanesliders_permissions-sliders' . $component, 0, 'cookie') . ", show: "
 289              . JRequest::getInt('jpanesliders_permissions-sliders' . $component, 0, 'cookie') . ", alwaysHide:true, opacity: false}); });";
 290  
 291          JFactory::getDocument()->addScriptDeclaration($js);
 292  
 293          return implode("\n", $html);
 294      }
 295  
 296      /**
 297       * Get a list of the user groups.
 298       *
 299       * @return  array
 300       *
 301       * @since   11.1
 302       */
 303  	protected function getUserGroups()
 304      {
 305          // Initialise variables.
 306          $db = JFactory::getDBO();
 307          $query = $db->getQuery(true);
 308          $query->select('a.id AS value, a.title AS text, COUNT(DISTINCT b.id) AS level, a.parent_id')
 309              ->from('#__usergroups AS a')
 310              ->leftJoin($db->quoteName('#__usergroups') . ' AS b ON a.lft > b.lft AND a.rgt < b.rgt')
 311              ->group('a.id, a.title, a.lft, a.rgt, a.parent_id')
 312              ->order('a.lft ASC');
 313          $db->setQuery($query);
 314          $options = $db->loadObjectList();
 315  
 316          return $options;
 317      }
 318  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1