PageRenderTime 59ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/web herbalspa.net php/web herbalspa.net/libraries/joomla/form/fields/rules.php

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