1 <?php
2 3 4 5 6 7 8
9
10 defined('JPATH_PLATFORM') or die;
11
12 JLog::add('JHtmlRules is deprecated.', JLog::WARNING, 'deprecated');
13
14 15 16 17 18 19
20 abstract class JHtmlRules
21 {
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
38 public static function assetFormWidget($actions, $assetId = null, $parent = null, $control = 'jform[rules]', $idPrefix = 'jform_rules')
39 {
40 $images = static::_getImagesArray();
41
42
43 $groups = static::_getUserGroups();
44
45
46 $inheriting = JAccess::getAssetRules($parent ?: static::_getParentAssetId($assetId), true);
47 $inherited = JAccess::getAssetRules($assetId, true);
48 $rules = JAccess::getAssetRules($assetId);
49
50 $html = array();
51
52 $html[] = '<div class="acl-options">';
53 $html[] = JHtml::_('tabs.start', 'acl-rules-' . $assetId, array('useCookie' => 1));
54 $html[] = JHtml::_('tabs.panel', JText::_('JLIB_HTML_ACCESS_SUMMARY'), 'summary');
55 $html[] = ' <p>' . JText::_('JLIB_HTML_ACCESS_SUMMARY_DESC') . '</p>';
56 $html[] = ' <table class="aclsummary-table" summary="' . JText::_('JLIB_HTML_ACCESS_SUMMARY_DESC') . '">';
57 $html[] = ' <caption>' . JText::_('JLIB_HTML_ACCESS_SUMMARY_DESC_CAPTION') . '</caption>';
58 $html[] = ' <tr>';
59 $html[] = ' <th class="col1 hidelabeltxt">' . JText::_('JLIB_RULES_GROUPS') . '</th>';
60
61 foreach ($actions as $i => $action)
62 {
63 $html[] = ' <th class="col' . ($i + 2) . '">' . JText::_($action->title) . '</th>';
64 }
65
66 $html[] = ' </tr>';
67
68 foreach ($groups as $i => $group)
69 {
70 $html[] = ' <tr class="row' . ($i % 2) . '">';
71 $html[] = ' <td class="col1">' . $group->text . '</td>';
72
73 foreach ($actions as $j => $action)
74 {
75 $html[] = ' <td class="col' . ($j + 2) . '">'
76 . ($assetId ? ($inherited->allow($action->name, $group->identities) ? $images['allow'] : $images['deny'])
77 : ($inheriting->allow($action->name, $group->identities) ? $images['allow'] : $images['deny'])) . '</td>';
78 }
79
80 $html[] = ' </tr>';
81 }
82
83 $html[] = ' </table>';
84
85 foreach ($actions as $action)
86 {
87 $actionTitle = JText::_($action->title);
88 $actionDesc = JText::_($action->description);
89 $html[] = JHtml::_('tabs.panel', $actionTitle, $action->name);
90 $html[] = ' <p>' . $actionDesc . '</p>';
91 $html[] = ' <table class="aclmodify-table" summary="' . strip_tags($actionDesc) . '">';
92 $html[] = ' <caption>' . JText::_('JLIB_HTML_ACCESS_MODIFY_DESC_CAPTION_ACL') . ' ' . $actionTitle . ' '
93 . JText::_('JLIB_HTML_ACCESS_MODIFY_DESC_CAPTION_TABLE') . '</caption>';
94 $html[] = ' <tr>';
95 $html[] = ' <th class="col1 hidelabeltxt">' . JText::_('JLIB_RULES_GROUP') . '</th>';
96 $html[] = ' <th class="col2">' . JText::_('JLIB_RULES_INHERIT') . '</th>';
97 $html[] = ' <th class="col3 hidelabeltxt">' . JText::_('JMODIFY') . '</th>';
98 $html[] = ' <th class="col4">' . JText::_('JCURRENT') . '</th>';
99 $html[] = ' </tr>';
100
101 foreach ($groups as $i => $group)
102 {
103 $selected = $rules->allow($action->name, $group->value);
104
105 $html[] = ' <tr class="row' . ($i % 2) . '">';
106 $html[] = ' <td class="col1">' . $group->text . '</td>';
107 $html[] = ' <td class="col2">'
108 . ($inheriting->allow($action->name, $group->identities) ? $images['allow-i'] : $images['deny-i']) . '</td>';
109 $html[] = ' <td class="col3">';
110 $html[] = ' <select id="' . $idPrefix . '_' . $action->name . '_' . $group->value
111 . '" class="inputbox" size="1" name="' . $control . '[' . $action->name . '][' . $group->value . ']" title="'
112 . JText::sprintf('JLIB_RULES_SELECT_ALLOW_DENY_GROUP', $actionTitle, $group->text) . '">';
113 $html[] = ' <option value=""' . ($selected === null ? ' selected="selected"' : '') . '>'
114 . JText::_('JLIB_RULES_INHERIT') . '</option>';
115 $html[] = ' <option value="1"' . ($selected === true ? ' selected="selected"' : '') . '>'
116 . JText::_('JLIB_RULES_ALLOWED') . '</option>';
117 $html[] = ' <option value="0"' . ($selected === false ? ' selected="selected"' : '') . '>'
118 . JText::_('JLIB_RULES_DENIED') . '</option>';
119 $html[] = ' </select>';
120 $html[] = ' </td>';
121 $html[] = ' <td class="col4">'
122 . ($assetId ? ($inherited->allow($action->name, $group->identities) ? $images['allow'] : $images['deny'])
123 : ($inheriting->allow($action->name, $group->identities) ? $images['allow'] : $images['deny'])) . '</td>';
124 $html[] = ' </tr>';
125 }
126
127 $html[] = ' </table>';
128 }
129
130 $html[] = JHtml::_('tabs.end');
131
132
133 $html[] = ' <div class="clr"></div>';
134 $html[] = ' <ul class="acllegend fltlft">';
135 $html[] = ' <li class="acl-allowed">' . JText::_('JLIB_RULES_ALLOWED') . '</li>';
136 $html[] = ' <li class="acl-denied">' . JText::_('JLIB_RULES_DENIED') . '</li>';
137 $html[] = ' </ul>';
138 $html[] = '</div>';
139
140 return implode("\n", $html);
141 }
142
143 144 145 146 147 148 149 150 151 152
153 protected static function _getParentAssetId($assetId)
154 {
155
156 $db = JFactory::getDbo();
157 $query = $db->getQuery(true);
158
159
160 $query->select($db->quoteName('parent_id'))
161 ->from($db->quoteName('#__assets'))
162 ->where($db->quoteName('id') . ' = ' . (int) $assetId);
163 $db->setQuery($query);
164
165 return (int) $db->loadResult();
166 }
167
168 169 170 171 172 173 174 175
176 protected static function _getUserGroups()
177 {
178
179 $db = JFactory::getDbo();
180
181
182 $db->setQuery(
183 'SELECT a.id AS value, a.title AS text, b.id as parent'
184 . ' FROM #__usergroups AS a LEFT JOIN #__usergroups AS b ON a.lft >= b.lft AND a.rgt <= b.rgt'
185 . ' ORDER BY a.lft ASC, b.lft ASC'
186 );
187 $result = $db->loadObjectList();
188 $options = array();
189
190
191 foreach ($result as $option)
192 {
193 $end = end($options);
194
195 if ($end === false || $end->value != $option->value)
196 {
197 $end = $option;
198 $end->level = 0;
199 $options[] = $end;
200 }
201 else
202 {
203 $end->level++;
204 }
205
206 $end->identities[] = $option->parent;
207 }
208
209 return $options;
210 }
211
212 213 214 215 216 217 218 219
220 protected static function _getImagesArray()
221 {
222 $images['allow-l'] = '<label class="icon-16-allow" title="' . JText::_('JLIB_RULES_ALLOWED') . '">' . JText::_('JLIB_RULES_ALLOWED')
223 . '</label>';
224 $images['deny-l'] = '<label class="icon-16-deny" title="' . JText::_('JLIB_RULES_DENIED') . '">' . JText::_('JLIB_RULES_DENIED') . '</label>';
225 $images['allow'] = '<a class="icon-16-allow" title="' . JText::_('JLIB_RULES_ALLOWED') . '"> </a>';
226 $images['deny'] = '<a class="icon-16-deny" title="' . JText::_('JLIB_RULES_DENIED') . '"> </a>';
227 $images['allow-i'] = '<a class="icon-16-allowinactive" title="' . JText::_('JRULE_ALLOWED_INHERITED') . '"> </a>';
228 $images['deny-i'] = '<a class="icon-16-denyinactive" title="' . JText::_('JRULE_DENIED_INHERITED') . '"> </a>';
229
230 return $images;
231 }
232 }
233