[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/libraries/joomla/html/html/ -> access.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 JHtmlAccess
  20  {
  21      /**
  22       * A cached array of the asset groups
  23       *
  24       * @var    array
  25       * @since  11.1
  26       */
  27      protected static $asset_groups = null;
  28  
  29      /**
  30       * Displays a list of the available access view levels
  31       *
  32       * @param   string  $name      The form field name.
  33       * @param   string  $selected  The name of the selected section.
  34       * @param   string  $attribs   Additional attributes to add to the select field.
  35       * @param   mixed   $params    True to add "All Sections" option or and array of options
  36       * @param   string  $id        The form field id
  37       *
  38       * @return  string  The required HTML for the SELECT tag.
  39       *
  40       * @since  11.1
  41       *
  42       * @see    JFormFieldAccessLevel
  43       */
  44  	public static function level($name, $selected, $attribs = '', $params = true, $id = false)
  45      {
  46          $db = JFactory::getDbo();
  47          $query = $db->getQuery(true);
  48  
  49          $query->select('a.id AS value, a.title AS text');
  50          $query->from('#__viewlevels AS a');
  51          $query->group('a.id, a.title, a.ordering');
  52          $query->order('a.ordering ASC');
  53          $query->order($query->qn('title') . ' ASC');
  54  
  55          // Get the options.
  56          $db->setQuery($query);
  57          $options = $db->loadObjectList();
  58  
  59          // Check for a database error.
  60          if ($db->getErrorNum())
  61          {
  62              JError::raiseWarning(500, $db->getErrorMsg());
  63              return null;
  64          }
  65  
  66          // If params is an array, push these options to the array
  67          if (is_array($params))
  68          {
  69              $options = array_merge($params, $options);
  70          }
  71          // If all levels is allowed, push it into the array.
  72          elseif ($params)
  73          {
  74              array_unshift($options, JHtml::_('select.option', '', JText::_('JOPTION_ACCESS_SHOW_ALL_LEVELS')));
  75          }
  76  
  77          return JHtml::_(
  78              'select.genericlist',
  79              $options,
  80              $name,
  81              array(
  82                  'list.attr' => $attribs,
  83                  'list.select' => $selected,
  84                  'id' => $id
  85              )
  86          );
  87      }
  88  
  89      /**
  90       * Displays a list of the available user groups.
  91       *
  92       * @param   string   $name      The form field name.
  93       * @param   string   $selected  The name of the selected section.
  94       * @param   string   $attribs   Additional attributes to add to the select field.
  95       * @param   boolean  $allowAll  True to add "All Groups" option.
  96       *
  97       * @return  string   The required HTML for the SELECT tag.
  98       *
  99       * @see     JFormFieldUsergroup
 100       *
 101       * @since   11.1
 102       */
 103  	public static function usergroup($name, $selected, $attribs = '', $allowAll = true)
 104      {
 105          $db = JFactory::getDbo();
 106          $query = $db->getQuery(true);
 107          $query->select('a.id AS value, a.title AS text, COUNT(DISTINCT b.id) AS level');
 108          $query->from($db->quoteName('#__usergroups') . ' AS a');
 109          $query->join('LEFT', $db->quoteName('#__usergroups') . ' AS b ON a.lft > b.lft AND a.rgt < b.rgt');
 110          $query->group('a.id, a.title, a.lft, a.rgt');
 111          $query->order('a.lft ASC');
 112          $db->setQuery($query);
 113          $options = $db->loadObjectList();
 114  
 115          // Check for a database error.
 116          if ($db->getErrorNum())
 117          {
 118              JError::raiseNotice(500, $db->getErrorMsg());
 119              return null;
 120          }
 121  
 122          for ($i = 0, $n = count($options); $i < $n; $i++)
 123          {
 124              $options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->text;
 125          }
 126  
 127          // If all usergroups is allowed, push it into the array.
 128          if ($allowAll)
 129          {
 130              array_unshift($options, JHtml::_('select.option', '', JText::_('JOPTION_ACCESS_SHOW_ALL_GROUPS')));
 131          }
 132  
 133          return JHtml::_('select.genericlist', $options, $name, array('list.attr' => $attribs, 'list.select' => $selected));
 134      }
 135  
 136      /**
 137       * Returns a UL list of user groups with check boxes
 138       *
 139       * @param   string   $name             The name of the checkbox controls array
 140       * @param   array    $selected         An array of the checked boxes
 141       * @param   boolean  $checkSuperAdmin  If false only super admins can add to super admin groups
 142       *
 143       * @return  string
 144       *
 145       * @since   11.1
 146       */
 147  	public static function usergroups($name, $selected, $checkSuperAdmin = false)
 148      {
 149          static $count;
 150  
 151          $count++;
 152  
 153          $isSuperAdmin = JFactory::getUser()->authorise('core.admin');
 154  
 155          $db = JFactory::getDbo();
 156          $query = $db->getQuery(true);
 157          $query->select('a.*, COUNT(DISTINCT b.id) AS level');
 158          $query->from($db->quoteName('#__usergroups') . ' AS a');
 159          $query->join('LEFT', $db->quoteName('#__usergroups') . ' AS b ON a.lft > b.lft AND a.rgt < b.rgt');
 160          $query->group('a.id, a.title, a.lft, a.rgt, a.parent_id');
 161          $query->order('a.lft ASC');
 162          $db->setQuery($query);
 163          $groups = $db->loadObjectList();
 164  
 165          // Check for a database error.
 166          if ($db->getErrorNum())
 167          {
 168              JError::raiseNotice(500, $db->getErrorMsg());
 169              return null;
 170          }
 171  
 172          $html = array();
 173  
 174          $html[] = '<ul class="checklist usergroups">';
 175  
 176          for ($i = 0, $n = count($groups); $i < $n; $i++)
 177          {
 178              $item = &$groups[$i];
 179  
 180              // If checkSuperAdmin is true, only add item if the user is superadmin or the group is not super admin
 181              if ((!$checkSuperAdmin) || $isSuperAdmin || (!JAccess::checkGroup($item->id, 'core.admin')))
 182              {
 183                  // Setup  the variable attributes.
 184                  $eid = $count . 'group_' . $item->id;
 185                  // Don't call in_array unless something is selected
 186                  $checked = '';
 187                  if ($selected)
 188                  {
 189                      $checked = in_array($item->id, $selected) ? ' checked="checked"' : '';
 190                  }
 191                  $rel = ($item->parent_id > 0) ? ' rel="' . $count . 'group_' . $item->parent_id . '"' : '';
 192  
 193                  // Build the HTML for the item.
 194                  $html[] = '    <li>';
 195                  $html[] = '        <input type="checkbox" name="' . $name . '[]" value="' . $item->id . '" id="' . $eid . '"';
 196                  $html[] = '                ' . $checked . $rel . ' />';
 197                  $html[] = '        <label for="' . $eid . '">';
 198                  $html[] = '        ' . str_repeat('<span class="gi">|&mdash;</span>', $item->level) . $item->title;
 199                  $html[] = '        </label>';
 200                  $html[] = '    </li>';
 201              }
 202          }
 203          $html[] = '</ul>';
 204  
 205          return implode("\n", $html);
 206      }
 207  
 208      /**
 209       * Returns a UL list of actions with check boxes
 210       *
 211       * @param   string  $name       The name of the checkbox controls array
 212       * @param   array   $selected   An array of the checked boxes
 213       * @param   string  $component  The component the permissions apply to
 214       * @param   string  $section    The section (within a component) the permissions apply to
 215       *
 216       * @return  string
 217       *
 218       * @see     JAccess
 219       * @since   11.1
 220       */
 221  	public static function actions($name, $selected, $component, $section = 'global')
 222      {
 223          static $count;
 224  
 225          $count++;
 226  
 227          $actions = JAccess::getActions($component, $section);
 228  
 229          $html = array();
 230          $html[] = '<ul class="checklist access-actions">';
 231  
 232          for ($i = 0, $n = count($actions); $i < $n; $i++)
 233          {
 234              $item = &$actions[$i];
 235  
 236              // Setup  the variable attributes.
 237              $eid = $count . 'action_' . $item->id;
 238              $checked = in_array($item->id, $selected) ? ' checked="checked"' : '';
 239  
 240              // Build the HTML for the item.
 241              $html[] = '    <li>';
 242              $html[] = '        <input type="checkbox" name="' . $name . '[]" value="' . $item->id . '" id="' . $eid . '"';
 243              $html[] = '            ' . $checked . ' />';
 244              $html[] = '        <label for="' . $eid . '">';
 245              $html[] = '            ' . JText::_($item->title);
 246              $html[] = '        </label>';
 247              $html[] = '    </li>';
 248          }
 249          $html[] = '</ul>';
 250  
 251          return implode("\n", $html);
 252      }
 253  
 254      /**
 255       * Gets a list of the asset groups as an array of JHtml compatible options.
 256       *
 257       * @param   array  $config  An array of options for the options
 258       *
 259       * @return  mixed  An array or false if an error occurs
 260       *
 261       * @since   11.1
 262       */
 263  	public static function assetgroups($config = array())
 264      {
 265          if (empty(JHtmlAccess::$asset_groups))
 266          {
 267              $db = JFactory::getDbo();
 268              $query = $db->getQuery(true);
 269  
 270              $query->select('a.id AS value, a.title AS text');
 271              $query->from($db->quoteName('#__viewlevels') . ' AS a');
 272              $query->group('a.id, a.title, a.ordering');
 273              $query->order('a.ordering ASC');
 274  
 275              $db->setQuery($query);
 276              JHtmlAccess::$asset_groups = $db->loadObjectList();
 277  
 278              // Check for a database error.
 279              if ($db->getErrorNum())
 280              {
 281                  JError::raiseNotice(500, $db->getErrorMsg());
 282                  return false;
 283              }
 284          }
 285  
 286          return JHtmlAccess::$asset_groups;
 287      }
 288  
 289      /**
 290       * Displays a Select list of the available asset groups
 291       *
 292       * @param   string  $name      The name of the select element
 293       * @param   mixed   $selected  The selected asset group id
 294       * @param   string  $attribs   Optional attributes for the select field
 295       * @param   array   $config    An array of options for the control
 296       *
 297       * @return  mixed  An HTML string or null if an error occurs
 298       *
 299       * @since   11.1
 300       */
 301  	public static function assetgrouplist($name, $selected, $attribs = null, $config = array())
 302      {
 303          static $count;
 304  
 305          $options = JHtmlAccess::assetgroups();
 306          if (isset($config['title']))
 307          {
 308              array_unshift($options, JHtml::_('select.option', '', $config['title']));
 309          }
 310  
 311          return JHtml::_(
 312              'select.genericlist',
 313              $options,
 314              $name,
 315              array(
 316                  'id' => isset($config['id']) ? $config['id'] : 'assetgroups_' . ++$count,
 317                  'list.attr' => (is_null($attribs) ? 'class="inputbox" size="3"' : $attribs),
 318                  'list.select' => (int) $selected
 319              )
 320          );
 321      }
 322  }


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