1 <?php
2 3 4 5 6 7 8
9
10 defined('JPATH_PLATFORM') or die;
11
12 13 14 15 16
17 abstract class JHtmlAccess
18 {
19 20 21 22 23 24
25 protected static $asset_groups = null;
26
27 28 29 30 31 32 33 34 35 36 37 38 39 40
41 public static function level($name, $selected, $attribs = '', $params = true, $id = false)
42 {
43 $db = JFactory::getDbo();
44 $query = $db->getQuery(true)
45 ->select($db->quoteName('a.id', 'value') . ', ' . $db->quoteName('a.title', 'text'))
46 ->from($db->quoteName('#__viewlevels', 'a'))
47 ->group($db->quoteName(array('a.id', 'a.title', 'a.ordering')))
48 ->order($db->quoteName('a.ordering') . ' ASC')
49 ->order($db->quoteName('title') . ' ASC');
50
51
52 $db->setQuery($query);
53 $options = $db->loadObjectList();
54
55
56 if (is_array($params))
57 {
58 $options = array_merge($params, $options);
59 }
60
61
62 elseif ($params)
63 {
64 array_unshift($options, JHtml::_('select.option', '', JText::_('JOPTION_ACCESS_SHOW_ALL_LEVELS')));
65 }
66
67 return JHtml::_(
68 'select.genericlist',
69 $options,
70 $name,
71 array(
72 'list.attr' => $attribs,
73 'list.select' => $selected,
74 'id' => $id,
75 )
76 );
77 }
78
79 80 81 82 83 84 85 86 87 88 89 90 91 92
93 public static function usergroup($name, $selected, $attribs = '', $allowAll = true, $id = false)
94 {
95 $options = array_values(JHelperUsergroups::getInstance()->getAll());
96
97 for ($i = 0, $n = count($options); $i < $n; $i++)
98 {
99 $options[$i]->value = $options[$i]->id;
100 $options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->title;
101 }
102
103
104 if ($allowAll)
105 {
106 array_unshift($options, JHtml::_('select.option', '', JText::_('JOPTION_ACCESS_SHOW_ALL_GROUPS')));
107 }
108
109 return JHtml::_('select.genericlist', $options, $name, array('list.attr' => $attribs, 'list.select' => $selected, 'id' => $id));
110 }
111
112 113 114 115 116 117 118 119 120 121 122
123 public static function usergroups($name, $selected, $checkSuperAdmin = false)
124 {
125 static $count;
126
127 $count++;
128
129 $isSuperAdmin = JFactory::getUser()->authorise('core.admin');
130
131 $groups = array_values(JHelperUsergroups::getInstance()->getAll());
132
133 $html = array();
134
135 for ($i = 0, $n = count($groups); $i < $n; $i++)
136 {
137 $item = &$groups[$i];
138
139
140 if ((!$checkSuperAdmin) || $isSuperAdmin || (!JAccess::checkGroup($item->id, 'core.admin')))
141 {
142
143 $eid = $count . 'group_' . $item->id;
144
145
146 $checked = '';
147
148 if ($selected)
149 {
150 $checked = in_array($item->id, $selected) ? ' checked="checked"' : '';
151 }
152
153 $rel = ($item->parent_id > 0) ? ' rel="' . $count . 'group_' . $item->parent_id . '"' : '';
154
155
156 $html[] = ' <div class="control-group">';
157 $html[] = ' <div class="controls">';
158 $html[] = ' <label class="checkbox" for="' . $eid . '">';
159 $html[] = ' <input type="checkbox" name="' . $name . '[]" value="' . $item->id . '" id="' . $eid . '"';
160 $html[] = ' ' . $checked . $rel . ' />';
161 $html[] = ' ' . JLayoutHelper::render('joomla.html.treeprefix', array('level' => $item->level + 1)) . $item->title;
162 $html[] = ' </label>';
163 $html[] = ' </div>';
164 $html[] = ' </div>';
165 }
166 }
167
168 return implode("\n", $html);
169 }
170
171 172 173 174 175 176 177 178 179 180 181 182 183
184 public static function actions($name, $selected, $component, $section = 'global')
185 {
186 static $count;
187
188 $count++;
189
190 $actions = JAccess::getActionsFromFile(
191 JPATH_ADMINISTRATOR . '/components/' . $component . '/access.xml',
192 "/access/section[@name='" . $section . "']/"
193 );
194
195 $html = array();
196 $html[] = '<ul class="checklist access-actions">';
197
198 for ($i = 0, $n = count($actions); $i < $n; $i++)
199 {
200 $item = &$actions[$i];
201
202
203 $eid = $count . 'action_' . $item->id;
204 $checked = in_array($item->id, $selected) ? ' checked="checked"' : '';
205
206
207 $html[] = ' <li>';
208 $html[] = ' <input type="checkbox" name="' . $name . '[]" value="' . $item->id . '" id="' . $eid . '"';
209 $html[] = ' ' . $checked . ' />';
210 $html[] = ' <label for="' . $eid . '">';
211 $html[] = ' ' . JText::_($item->title);
212 $html[] = ' </label>';
213 $html[] = ' </li>';
214 }
215
216 $html[] = '</ul>';
217
218 return implode("\n", $html);
219 }
220
221 222 223 224 225 226 227
228 public static function assetgroups()
229 {
230 if (empty(static::$asset_groups))
231 {
232 $db = JFactory::getDbo();
233 $query = $db->getQuery(true)
234 ->select('a.id AS value, a.title AS text')
235 ->from($db->quoteName('#__viewlevels') . ' AS a')
236 ->group('a.id, a.title, a.ordering')
237 ->order('a.ordering ASC');
238
239 $db->setQuery($query);
240 static::$asset_groups = $db->loadObjectList();
241 }
242
243 return static::$asset_groups;
244 }
245
246 247 248 249 250 251 252 253 254 255 256 257
258 public static function assetgrouplist($name, $selected, $attribs = null, $config = array())
259 {
260 static $count;
261
262 $options = static::assetgroups();
263
264 if (isset($config['title']))
265 {
266 array_unshift($options, JHtml::_('select.option', '', $config['title']));
267 }
268
269 return JHtml::_(
270 'select.genericlist',
271 $options,
272 $name,
273 array(
274 'id' => isset($config['id']) ? $config['id'] : 'assetgroups_' . (++$count),
275 'list.attr' => $attribs === null ? 'class="inputbox" size="3"' : $attribs,
276 'list.select' => (int) $selected,
277 )
278 );
279 }
280 }
281