[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/libraries/joomla/html/html/ -> rules.php (source)

   1  <?php
   2  /**
   3   * @package     Joomla.Platform
   4   * @subpackage  HTML
   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   * Extended Utility class for all HTML drawing classes.
  14   *
  15   * @package     Joomla.Platform
  16   * @subpackage  HTML
  17   * @since       11.1
  18   */
  19  abstract class JHtmlRules
  20  {
  21      /**
  22       * Creates the HTML for the permissions widget
  23       *
  24       * @param   array    $actions   Array of action objects
  25       * @param   integer  $assetId   Id of a specific asset to  create a widget for.
  26       * @param   integer  $parent    Id of the parent of the asset
  27       * @param   string   $control   The form control
  28       * @param   string   $idPrefix  Prefix for the ids assigned to specific action-group pairs
  29       *
  30       * @return  string   HTML for the permissions widget
  31       *
  32       * @since   11.1
  33       *
  34       * @see     JAccess
  35       * @see     JFormFieldRules
  36       */
  37  	public static function assetFormWidget($actions, $assetId = null, $parent = null, $control = 'jform[rules]', $idPrefix = 'jform_rules')
  38      {
  39          $images = self::_getImagesArray();
  40  
  41          // Get the user groups.
  42          $groups = self::_getUserGroups();
  43  
  44          // Get the incoming inherited rules as well as the asset specific rules.
  45          $inheriting = JAccess::getAssetRules($parent ? $parent : self::_getParentAssetId($assetId), true);
  46          $inherited = JAccess::getAssetRules($assetId, true);
  47          $rules = JAccess::getAssetRules($assetId);
  48  
  49          $html = array();
  50  
  51          $html[] = '<div class="acl-options">';
  52          $html[] = JHtml::_('tabs.start', 'acl-rules-' . $assetId, array('useCookie' => 1));
  53          $html[] = JHtml::_('tabs.panel', JText::_('JLIB_HTML_ACCESS_SUMMARY'), 'summary');
  54          $html[] = '            <p>' . JText::_('JLIB_HTML_ACCESS_SUMMARY_DESC') . '</p>';
  55          $html[] = '            <table class="aclsummary-table" summary="' . JText::_('JLIB_HTML_ACCESS_SUMMARY_DESC') . '">';
  56          $html[] = '            <caption>' . JText::_('JLIB_HTML_ACCESS_SUMMARY_DESC_CAPTION') . '</caption>';
  57          $html[] = '            <tr>';
  58          $html[] = '                <th class="col1 hidelabeltxt">' . JText::_('JLIB_RULES_GROUPS') . '</th>';
  59          foreach ($actions as $i => $action)
  60          {
  61              $html[] = '                <th class="col' . ($i + 2) . '">' . JText::_($action->title) . '</th>';
  62          }
  63          $html[] = '            </tr>';
  64  
  65          foreach ($groups as $i => $group)
  66          {
  67              $html[] = '            <tr class="row' . ($i % 2) . '">';
  68              $html[] = '                <td class="col1">' . $group->text . '</td>';
  69              foreach ($actions as $i => $action)
  70              {
  71                  $html[] = '                <td class="col' . ($i + 2) . '">'
  72                      . ($assetId ? ($inherited->allow($action->name, $group->identities) ? $images['allow'] : $images['deny'])
  73                      : ($inheriting->allow($action->name, $group->identities) ? $images['allow'] : $images['deny'])) . '</td>';
  74              }
  75              $html[] = '            </tr>';
  76          }
  77  
  78          $html[] = '         </table>';
  79  
  80          foreach ($actions as $action)
  81          {
  82              $actionTitle = JText::_($action->title);
  83              $actionDesc = JText::_($action->description);
  84              $html[] = JHtml::_('tabs.panel', $actionTitle, $action->name);
  85              $html[] = '            <p>' . $actionDesc . '</p>';
  86              $html[] = '            <table class="aclmodify-table" summary="' . strip_tags($actionDesc) . '">';
  87              $html[] = '            <caption>' . JText::_('JLIB_HTML_ACCESS_MODIFY_DESC_CAPTION_ACL') . ' ' . $actionTitle . ' '
  88                  . JText::_('JLIB_HTML_ACCESS_MODIFY_DESC_CAPTION_TABLE') . '</caption>';
  89              $html[] = '            <tr>';
  90              $html[] = '                <th class="col1 hidelabeltxt">' . JText::_('JLIB_RULES_GROUP') . '</th>';
  91              $html[] = '                <th class="col2">' . JText::_('JLIB_RULES_INHERIT') . '</th>';
  92              $html[] = '                <th class="col3 hidelabeltxt">' . JText::_('JMODIFY') . '</th>';
  93              $html[] = '                <th class="col4">' . JText::_('JCURRENT') . '</th>';
  94              $html[] = '            </tr>';
  95  
  96              foreach ($groups as $i => $group)
  97              {
  98                  $selected = $rules->allow($action->name, $group->value);
  99  
 100                  $html[] = '            <tr class="row' . ($i % 2) . '">';
 101                  $html[] = '                <td class="col1">' . $group->text . '</td>';
 102                  $html[] = '                <td class="col2">'
 103                      . ($inheriting->allow($action->name, $group->identities) ? $images['allow-i'] : $images['deny-i']) . '</td>';
 104                  $html[] = '                <td class="col3">';
 105                  $html[] = '                    <select id="' . $idPrefix . '_' . $action->name . '_' . $group->value
 106                      . '" class="inputbox" size="1" name="' . $control . '[' . $action->name . '][' . $group->value . ']" title="'
 107                      . JText::sprintf('JLIB_RULES_SELECT_ALLOW_DENY_GROUP', $actionTitle, $group->text) . '">';
 108                  $html[] = '                        <option value=""' . ($selected === null ? ' selected="selected"' : '') . '>'
 109                      . JText::_('JLIB_RULES_INHERIT') . '</option>';
 110                  $html[] = '                        <option value="1"' . ($selected === true ? ' selected="selected"' : '') . '>'
 111                      . JText::_('JLIB_RULES_ALLOWED') . '</option>';
 112                  $html[] = '                        <option value="0"' . ($selected === false ? ' selected="selected"' : '') . '>'
 113                      . JText::_('JLIB_RULES_DENIED') . '</option>';
 114                  $html[] = '                    </select>';
 115                  $html[] = '                </td>';
 116                  $html[] = '                <td class="col4">'
 117                      . ($assetId ? ($inherited->allow($action->name, $group->identities) ? $images['allow'] : $images['deny'])
 118                      : ($inheriting->allow($action->name, $group->identities) ? $images['allow'] : $images['deny'])) . '</td>';
 119                  $html[] = '            </tr>';
 120              }
 121  
 122              $html[] = '            </table>';
 123          }
 124  
 125          $html[] = JHtml::_('tabs.end');
 126  
 127          // Build the footer with legend and special purpose buttons.
 128          $html[] = '    <div class="clr"></div>';
 129          $html[] = '    <ul class="acllegend fltlft">';
 130          $html[] = '        <li class="acl-allowed">' . JText::_('JLIB_RULES_ALLOWED') . '</li>';
 131          $html[] = '        <li class="acl-denied">' . JText::_('JLIB_RULES_DENIED') . '</li>';
 132          $html[] = '    </ul>';
 133          $html[] = '</div>';
 134  
 135          return implode("\n", $html);
 136      }
 137  
 138      /**
 139       * Get the id of the parent asset
 140       *
 141       * @param   integer  $assetId  The asset for which the parentid will be returned
 142       *
 143       * @return  integer  The id of the parent asset
 144       *
 145       * @since   11.1
 146       */
 147  	protected static function _getParentAssetId($assetId)
 148      {
 149          // Get a database object.
 150          $db = JFactory::getDBO();
 151          $query = $db->getQuery(true);
 152  
 153          // Get the user groups from the database.
 154          $query->select($db->quoteName('parent_id'));
 155          $query->from($db->quoteName('#__assets'));
 156          $query->where($db->quoteName('id') . ' = ' . (int) $assetId);
 157          $db->setQuery($query);
 158          return (int) $db->loadResult();
 159      }
 160  
 161      /**
 162       * Get the user groups
 163       *
 164       * @return  array  Array of user groups
 165       *
 166       * @since   11.1
 167       */
 168  	protected static function _getUserGroups()
 169      {
 170          // Get a database object.
 171          $db = JFactory::getDBO();
 172  
 173          // Get the user groups from the database.
 174          $db->setQuery(
 175              'SELECT a.id AS value, a.title AS text, b.id as parent'
 176              . ' FROM #__usergroups AS a' . ' LEFT JOIN #__usergroups AS b ON a.lft >= b.lft AND a.rgt <= b.rgt'
 177              . ' ORDER BY a.lft ASC, b.lft ASC'
 178          );
 179          $result = $db->loadObjectList();
 180          $options = array();
 181  
 182          // Pre-compute additional values.
 183          foreach ($result as $option)
 184          {
 185              $end = end($options);
 186              if ($end === false || $end->value != $option->value)
 187              {
 188                  $end = $option;
 189                  $end->level = 0;
 190                  $options[] = $end;
 191              }
 192              else
 193              {
 194                  $end->level++;
 195              }
 196              $end->identities[] = $option->parent;
 197          }
 198  
 199          return $options;
 200      }
 201  
 202      /**
 203       * Get the array of images associate with specific permissions
 204       *
 205       * @return  array  An associative  array of permissions and images
 206       *
 207       * @since   11.1
 208       */
 209  	protected static function _getImagesArray()
 210      {
 211          $images['allow-l'] = '<label class="icon-16-allow" title="' . JText::_('JLIB_RULES_ALLOWED') . '">' . JText::_('JLIB_RULES_ALLOWED')
 212              . '</label>';
 213          $images['deny-l'] = '<label class="icon-16-deny" title="' . JText::_('JLIB_RULES_DENIED') . '">' . JText::_('JLIB_RULES_DENIED') . '</label>';
 214          $images['allow'] = '<a class="icon-16-allow" title="' . JText::_('JLIB_RULES_ALLOWED') . '"> </a>';
 215          $images['deny'] = '<a class="icon-16-deny" title="' . JText::_('JLIB_RULES_DENIED') . '"> </a>';
 216          $images['allow-i'] = '<a class="icon-16-allowinactive" title="' . JText::_('JRULE_ALLOWED_INHERITED') . '"> </a>';
 217          $images['deny-i'] = '<a class="icon-16-denyinactive" title="' . JText::_('JRULE_DENIED_INHERITED') . '"> </a>';
 218  
 219          return $images;
 220      }
 221  }


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