10 defined(
'JPATH_PLATFORM') or die;
29 protected $type =
'Rules';
64 public function __get($name)
74 return parent::__get($name);
87 public function __set($name, $value)
94 $this->$name = (string) $value;
98 parent::__set($name, $value);
116 public function setup(SimpleXMLElement $element, $value, $group = null)
118 $return = parent::setup($element, $value, $group);
122 $this->section = $this->element[
'section'] ? (string) $this->element[
'section'] :
'';
123 $this->component = $this->element[
'component'] ? (string) $this->element[
'component'] :
'';
124 $this->assetField = $this->element[
'asset_field'] ? (string) $this->element[
'asset_field'] :
'asset_id';
139 protected function getInput()
141 JHtml::_(
'bootstrap.tooltip');
144 $section = $this->section;
145 $component = $this->component;
146 $assetField = $this->assetField;
152 foreach ($this->element->children() as $el)
154 if ($el->getName() ==
'action')
156 $actions[] = (object) array(
'name' => (
string) $el[
'name'],
'title' => (string) $el[
'title'],
157 'description' => (
string) $el[
'description']);
162 if ($section ==
'component')
166 $query = $db->getQuery(
true)
167 ->select($db->quoteName(
'id'))
168 ->from($db->quoteName(
'#__assets'))
169 ->where($db->quoteName(
'name') .
' = ' . $db->quote($component));
170 $db->setQuery($query);
171 $assetId = (int) $db->loadResult();
177 $assetId = $this->form->getValue($assetField);
186 $groups = $this->getUserGroups();
192 $html[] =
'<p class="rule-desc">' .
JText::_(
'JLIB_RULES_SETTINGS_DESC') .
'</p>';
195 $html[] =
'<div id="permissions-sliders" class="tabbable tabs-left">';
198 $html[] =
'<ul class="nav nav-tabs">';
200 foreach ($groups as $group)
205 if ($group->value == 1)
210 $html[] =
'<li class="' . $active .
'">';
211 $html[] =
'<a href="#permission-' . $group->value .
'" data-toggle="tab">';
212 $html[] = str_repeat(
'<span class="level">–</span> ', $curLevel = $group->level) . $group->text;
219 $html[] =
'<div class="tab-content">';
222 foreach ($groups as $group)
227 if ($group->value == 1)
232 $html[] =
'<div class="tab-pane' . $active .
'" id="permission-' . $group->value .
'">';
233 $html[] =
'<table class="table table-striped">';
237 $html[] =
'<th class="actions" id="actions-th' . $group->value .
'">';
238 $html[] =
'<span class="acl-action">' .
JText::_(
'JLIB_RULES_ACTION') .
'</span>';
241 $html[] =
'<th class="settings" id="settings-th' . $group->value .
'">';
242 $html[] =
'<span class="acl-action">' .
JText::_(
'JLIB_RULES_SELECT_SETTING') .
'</span>';
246 $canCalculateSettings = ($group->parent_id || !empty($component));
248 if ($canCalculateSettings)
250 $html[] =
'<th id="aclactionth' . $group->value .
'">';
251 $html[] =
'<span class="acl-action">' .
JText::_(
'JLIB_RULES_CALCULATED_SETTING') .
'</span>';
256 $html[] =
'</thead>';
259 foreach ($actions as $action)
262 $html[] =
'<td headers="actions-th' . $group->value .
'">';
263 $html[] =
'<label for="' . $this->
id .
'_' . $action->name .
'_' . $group->value .
'" class="hasTooltip" title="'
264 . htmlspecialchars(
JText::_($action->title) .
' ' .
JText::_($action->description), ENT_COMPAT,
'UTF-8') .
'">';
266 $html[] =
'</label>';
269 $html[] =
'<td headers="settings-th' . $group->value .
'">';
271 $html[] =
'<select class="input-small" name="' . $this->name .
'[' . $action->name .
'][' . $group->value .
']" id="' . $this->
id .
'_' . $action->name
272 .
'_' . $group->value .
'" title="'
273 .
JText::sprintf(
'JLIB_RULES_SELECT_ALLOW_DENY_GROUP',
JText::_($action->title), trim($group->text)) .
'">';
278 $assetRule = $assetRules->allow($action->name, $group->value);
283 $html[] =
'<option value=""' . ($assetRule === null ?
' selected="selected"' :
'') .
'>'
284 .
JText::_(empty($group->parent_id) && empty($component) ?
'JLIB_RULES_NOT_SET' :
'JLIB_RULES_INHERITED') .
'</option>';
285 $html[] =
'<option value="1"' . ($assetRule ===
true ?
' selected="selected"' :
'') .
'>' .
JText::_(
'JLIB_RULES_ALLOWED')
287 $html[] =
'<option value="0"' . ($assetRule ===
false ?
' selected="selected"' :
'') .
'>' .
JText::_(
'JLIB_RULES_DENIED')
290 $html[] =
'</select>  ';
293 if (($assetRule ===
true) && ($inheritedRule ===
false))
295 $html[] =
JText::_(
'JLIB_RULES_CONFLICT');
302 if ($canCalculateSettings)
304 $html[] =
'<td headers="aclactionth' . $group->value .
'">';
311 if ($inheritedRule === null)
313 $html[] =
'<span class="label label-important">' .
JText::_(
'JLIB_RULES_NOT_ALLOWED') .
'</span>';
315 elseif ($inheritedRule ===
true)
317 $html[] =
'<span class="label label-success">' .
JText::_(
'JLIB_RULES_ALLOWED') .
'</span>';
319 elseif ($inheritedRule ===
false)
321 if ($assetRule ===
false)
323 $html[] =
'<span class="label label-important">' .
JText::_(
'JLIB_RULES_NOT_ALLOWED') .
'</span>';
327 $html[] =
'<span class="label"><i class="icon-lock icon-white"></i> ' .
JText::_(
'JLIB_RULES_NOT_ALLOWED_LOCKED')
332 elseif (!empty($component))
334 $html[] =
'<span class="label label-success"><i class="icon-lock icon-white"></i> ' .
JText::_(
'JLIB_RULES_ALLOWED_ADMIN')
341 if ($action->name ===
'core.admin')
343 $html[] =
'<span class="label label-success">' .
JText::_(
'JLIB_RULES_ALLOWED') .
'</span>';
345 elseif ($inheritedRule ===
false)
348 $html[] =
'<span class="label label-important"><i class="icon-lock icon-white"></i> '
349 .
JText::_(
'JLIB_RULES_NOT_ALLOWED_ADMIN_CONFLICT') .
'</span>';
353 $html[] =
'<span class="label label-success"><i class="icon-lock icon-white"></i> ' .
JText::_(
'JLIB_RULES_ALLOWED_ADMIN')
364 $html[] =
'</tbody>';
365 $html[] =
'</table></div>';
368 $html[] =
'</div></div>';
370 $html[] =
'<div class="alert">';
372 if ($section ==
'component' || $section == null)
374 $html[] =
JText::_(
'JLIB_RULES_SETTING_NOTES');
378 $html[] =
JText::_(
'JLIB_RULES_SETTING_NOTES_ITEM');
383 return implode(
"\n", $html);
393 protected function getUserGroups()
396 $query = $db->getQuery(
true)
397 ->select(
'a.id AS value, a.title AS text, COUNT(DISTINCT b.id) AS level, a.parent_id')
398 ->from(
'#__usergroups AS a')
399 ->join(
'LEFT', $db->quoteName(
'#__usergroups') .
' AS b ON a.lft > b.lft AND a.rgt < b.rgt')
400 ->group(
'a.id, a.title, a.lft, a.rgt, a.parent_id')
401 ->order(
'a.lft ASC');
402 $db->setQuery($query);
403 $options = $db->loadObjectList();