1 <?php
2 3 4 5 6 7
8
9 defined('FOF_INCLUDED') or die;
10
11 JFormHelper::loadFieldClass('rules');
12
13 14 15 16 17 18 19
20 class FOFFormFieldRules extends JFormFieldRules implements FOFFormField
21 {
22 protected $static;
23
24 protected $repeatable;
25
26
27 public $item;
28
29
30 public $rowid;
31
32 33 34 35 36 37 38 39 40
41 public function __get($name)
42 {
43 switch ($name)
44 {
45
46 case 'static':
47 return '';
48 break;
49
50
51 case 'repeatable':
52 return '';
53 break;
54
55 default:
56 return parent::__get($name);
57 }
58 }
59
60 61 62 63 64 65 66 67
68 public function getStatic()
69 {
70 return '';
71 }
72
73 74 75 76 77 78 79 80
81 public function getRepeatable()
82 {
83 return '';
84 }
85
86 87 88 89 90 91 92 93 94
95 public function getInput()
96 {
97 if (version_compare(JVERSION, '3.0', 'ge'))
98 {
99 return $this->getInput3x();
100 }
101 else
102 {
103 return $this->getInput25();
104 }
105 }
106
107 protected function getInput25()
108 {
109 JHtml::_('behavior.tooltip');
110
111
112 $section = $this->element['section'] ? (string) $this->element['section'] : '';
113 $component = $this->element['component'] ? (string) $this->element['component'] : '';
114 $assetField = $this->element['asset_field'] ? (string) $this->element['asset_field'] : 'asset_id';
115
116
117 $actions = JAccess::getActions($component, $section);
118
119
120 foreach ($this->element->children() as $el)
121 {
122 if ($el->getName() == 'action')
123 {
124 $actions[] = (object) array('name' => (string) $el['name'], 'title' => (string) $el['title'],
125 'description' => (string) $el['description']);
126 }
127 }
128
129
130 if ($section == 'component')
131 {
132
133 $db = FOFPlatform::getInstance()->getDbo();
134 $query = $db->getQuery(true);
135 $query->select($db->quoteName('id'));
136 $query->from($db->quoteName('#__assets'));
137 $query->where($db->quoteName('name') . ' = ' . $db->quote($component));
138 $db->setQuery($query);
139 $assetId = (int) $db->loadResult();
140
141 if ($error = $db->getErrorMsg())
142 {
143 JError::raiseNotice(500, $error);
144 }
145 }
146 else
147 {
148
149
150 $assetId = $this->form->getValue($assetField);
151
152
153
154
155
156 if(!$assetId)
157 {
158 $table = $this->form->getModel()->getTable();
159 $assetId = $table->getAssetParentId();
160 }
161
162 }
163
164
165
166
167
168
169
170
171
172 $assetRules = JAccess::getAssetRules($assetId);
173
174
175 $groups = $this->getUserGroups();
176
177
178 $curLevel = 0;
179
180
181 $html = array();
182 $html[] = '<div id="permissions-sliders" class="pane-sliders">';
183 $html[] = '<p class="rule-desc">' . JText::_('JLIB_RULES_SETTINGS_DESC') . '</p>';
184 $html[] = '<ul id="rules">';
185
186
187 foreach ($groups as $group)
188 {
189 $difLevel = $group->level - $curLevel;
190
191 if ($difLevel > 0)
192 {
193 $html[] = '<li><ul>';
194 }
195 elseif ($difLevel < 0)
196 {
197 $html[] = str_repeat('</ul></li>', -$difLevel);
198 }
199
200 $html[] = '<li>';
201
202 $html[] = '<div class="panel">';
203 $html[] = '<h3 class="pane-toggler title"><a href="javascript:void(0);"><span>';
204 $html[] = str_repeat('<span class="level">|–</span> ', $curLevel = $group->level) . $group->text;
205 $html[] = '</span></a></h3>';
206 $html[] = '<div class="pane-slider content pane-hide">';
207 $html[] = '<div class="mypanel">';
208 $html[] = '<table class="group-rules">';
209 $html[] = '<thead>';
210 $html[] = '<tr>';
211
212 $html[] = '<th class="actions" id="actions-th' . $group->value . '">';
213 $html[] = '<span class="acl-action">' . JText::_('JLIB_RULES_ACTION') . '</span>';
214 $html[] = '</th>';
215
216 $html[] = '<th class="settings" id="settings-th' . $group->value . '">';
217 $html[] = '<span class="acl-action">' . JText::_('JLIB_RULES_SELECT_SETTING') . '</span>';
218 $html[] = '</th>';
219
220
221 $canCalculateSettings = ($group->parent_id || !empty($component));
222 if ($canCalculateSettings)
223 {
224 $html[] = '<th id="aclactionth' . $group->value . '">';
225 $html[] = '<span class="acl-action">' . JText::_('JLIB_RULES_CALCULATED_SETTING') . '</span>';
226 $html[] = '</th>';
227 }
228
229 $html[] = '</tr>';
230 $html[] = '</thead>';
231 $html[] = '<tbody>';
232
233 foreach ($actions as $action)
234 {
235 $html[] = '<tr>';
236 $html[] = '<td headers="actions-th' . $group->value . '">';
237 $html[] = '<label class="hasTip" for="' . $this->id . '_' . $action->name . '_' . $group->value . '" title="'
238 . htmlspecialchars(JText::_($action->title) . '::' . JText::_($action->description), ENT_COMPAT, 'UTF-8') . '">';
239 $html[] = JText::_($action->title);
240 $html[] = '</label>';
241 $html[] = '</td>';
242
243 $html[] = '<td headers="settings-th' . $group->value . '">';
244
245 $html[] = '<select name="' . $this->name . '[' . $action->name . '][' . $group->value . ']" id="' . $this->id . '_' . $action->name
246 . '_' . $group->value . '" title="'
247 . JText::sprintf('JLIB_RULES_SELECT_ALLOW_DENY_GROUP', JText::_($action->title), trim($group->text)) . '">';
248
249 $inheritedRule = JAccess::checkGroup($group->value, $action->name, $assetId);
250
251
252 $assetRule = $assetRules->allow($action->name, $group->value);
253
254
255
256
257 $html[] = '<option value=""' . ($assetRule === null ? ' selected="selected"' : '') . '>'
258 . JText::_(empty($group->parent_id) && empty($component) ? 'JLIB_RULES_NOT_SET' : 'JLIB_RULES_INHERITED') . '</option>';
259 $html[] = '<option value="1"' . ($assetRule === true ? ' selected="selected"' : '') . '>' . JText::_('JLIB_RULES_ALLOWED')
260 . '</option>';
261 $html[] = '<option value="0"' . ($assetRule === false ? ' selected="selected"' : '') . '>' . JText::_('JLIB_RULES_DENIED')
262 . '</option>';
263
264 $html[] = '</select>  ';
265
266
267 if (($assetRule === true) && ($inheritedRule === false))
268 {
269 $html[] = JText::_('JLIB_RULES_CONFLICT');
270 }
271
272 $html[] = '</td>';
273
274
275
276 if ($canCalculateSettings)
277 {
278 $html[] = '<td headers="aclactionth' . $group->value . '">';
279
280
281
282
283 if (JAccess::checkGroup($group->value, 'core.admin', $assetId) !== true)
284 {
285 if ($inheritedRule === null)
286 {
287 $html[] = '<span class="icon-16-unset">' . JText::_('JLIB_RULES_NOT_ALLOWED') . '</span>';
288 }
289 elseif ($inheritedRule === true)
290 {
291 $html[] = '<span class="icon-16-allowed">' . JText::_('JLIB_RULES_ALLOWED') . '</span>';
292 }
293 elseif ($inheritedRule === false)
294 {
295 if ($assetRule === false)
296 {
297 $html[] = '<span class="icon-16-denied">' . JText::_('JLIB_RULES_NOT_ALLOWED') . '</span>';
298 }
299 else
300 {
301 $html[] = '<span class="icon-16-denied"><span class="icon-16-locked">' . JText::_('JLIB_RULES_NOT_ALLOWED_LOCKED')
302 . '</span></span>';
303 }
304 }
305 }
306 elseif (!empty($component))
307 {
308 $html[] = '<span class="icon-16-allowed"><span class="icon-16-locked">' . JText::_('JLIB_RULES_ALLOWED_ADMIN')
309 . '</span></span>';
310 }
311 else
312 {
313
314
315 if ($action->name === 'core.admin')
316 {
317 $html[] = '<span class="icon-16-allowed">' . JText::_('JLIB_RULES_ALLOWED') . '</span>';
318 }
319 elseif ($inheritedRule === false)
320 {
321
322 $html[] = '<span class="icon-16-denied"><span class="icon-16-locked">'
323 . JText::_('JLIB_RULES_NOT_ALLOWED_ADMIN_CONFLICT') . '</span></span>';
324 }
325 else
326 {
327 $html[] = '<span class="icon-16-allowed"><span class="icon-16-locked">' . JText::_('JLIB_RULES_ALLOWED_ADMIN')
328 . '</span></span>';
329 }
330 }
331
332 $html[] = '</td>';
333 }
334
335 $html[] = '</tr>';
336 }
337
338 $html[] = '</tbody>';
339 $html[] = '</table></div>';
340
341 $html[] = '</div></div>';
342 $html[] = '</li>';
343
344 }
345
346 $html[] = str_repeat('</ul></li>', $curLevel);
347 $html[] = '</ul><div class="rule-notes">';
348 if ($section == 'component' || $section == null)
349 {
350 $html[] = JText::_('JLIB_RULES_SETTING_NOTES');
351 }
352 else
353 {
354 $html[] = JText::_('JLIB_RULES_SETTING_NOTES_ITEM');
355 }
356 $html[] = '</div></div>';
357
358 $js = "window.addEvent('domready', function(){ new Fx.Accordion($$('div#permissions-sliders.pane-sliders .panel h3.pane-toggler'),"
359 . "$$('div#permissions-sliders.pane-sliders .panel div.pane-slider'), {onActive: function(toggler, i) {toggler.addClass('pane-toggler-down');"
360 . "toggler.removeClass('pane-toggler');i.addClass('pane-down');i.removeClass('pane-hide');Cookie.write('jpanesliders_permissions-sliders"
361 . $component
362 . "',$$('div#permissions-sliders.pane-sliders .panel h3').indexOf(toggler));},"
363 . "onBackground: function(toggler, i) {toggler.addClass('pane-toggler');toggler.removeClass('pane-toggler-down');i.addClass('pane-hide');"
364 . "i.removeClass('pane-down');}, duration: 300, display: "
365 . JRequest::getInt('jpanesliders_permissions-sliders' . $component, 0, 'cookie') . ", show: "
366 . JRequest::getInt('jpanesliders_permissions-sliders' . $component, 0, 'cookie') . ", alwaysHide:true, opacity: false}); });";
367
368 JFactory::getDocument()->addScriptDeclaration($js);
369
370 return implode("\n", $html);
371 }
372
373 protected function getInput3x()
374 {
375 JHtml::_('bootstrap.tooltip');
376
377
378 $section = $this->section;
379 $component = $this->component;
380 $assetField = $this->assetField;
381
382
383 $actions = JAccess::getActions($component, $section);
384
385
386 foreach ($this->element->children() as $el)
387 {
388 if ($el->getName() == 'action')
389 {
390 $actions[] = (object) array('name' => (string) $el['name'], 'title' => (string) $el['title'],
391 'description' => (string) $el['description']);
392 }
393 }
394
395
396 if ($section == 'component')
397 {
398
399 $db = FOFPlatform::getInstance()->getDbo();
400 $query = $db->getQuery(true)
401 ->select($db->quoteName('id'))
402 ->from($db->quoteName('#__assets'))
403 ->where($db->quoteName('name') . ' = ' . $db->quote($component));
404
405 $assetId = (int) $db->setQuery($query)->loadResult();
406 }
407 else
408 {
409
410
411 $assetId = $this->form->getValue($assetField);
412
413
414
415
416
417 if(!$assetId)
418 {
419 $table = $this->form->getModel()->getTable();
420 $assetId = $table->getAssetParentId();
421 }
422
423 }
424
425
426
427
428 $assetRules = JAccess::getAssetRules($assetId);
429
430
431 $groups = $this->getUserGroups();
432
433
434 $html = array();
435
436
437 $html[] = '<p class="rule-desc">' . JText::_('JLIB_RULES_SETTINGS_DESC') . '</p>';
438
439
440 $html[] = '<div id="permissions-sliders" class="tabbable tabs-left">';
441
442
443 $html[] = '<ul class="nav nav-tabs">';
444
445 foreach ($groups as $group)
446 {
447
448 $active = "";
449
450 if ($group->value == 1)
451 {
452 $active = "active";
453 }
454
455 $html[] = '<li class="' . $active . '">';
456 $html[] = '<a href="#permission-' . $group->value . '" data-toggle="tab">';
457 $html[] = str_repeat('<span class="level">–</span> ', $curLevel = $group->level) . $group->text;
458 $html[] = '</a>';
459 $html[] = '</li>';
460 }
461
462 $html[] = '</ul>';
463
464 $html[] = '<div class="tab-content">';
465
466
467 foreach ($groups as $group)
468 {
469
470 $active = "";
471
472 if ($group->value == 1)
473 {
474 $active = " active";
475 }
476
477 $html[] = '<div class="tab-pane' . $active . '" id="permission-' . $group->value . '">';
478 $html[] = '<table class="table table-striped">';
479 $html[] = '<thead>';
480 $html[] = '<tr>';
481
482 $html[] = '<th class="actions" id="actions-th' . $group->value . '">';
483 $html[] = '<span class="acl-action">' . JText::_('JLIB_RULES_ACTION') . '</span>';
484 $html[] = '</th>';
485
486 $html[] = '<th class="settings" id="settings-th' . $group->value . '">';
487 $html[] = '<span class="acl-action">' . JText::_('JLIB_RULES_SELECT_SETTING') . '</span>';
488 $html[] = '</th>';
489
490
491 $canCalculateSettings = ($group->parent_id || !empty($component));
492
493 if ($canCalculateSettings)
494 {
495 $html[] = '<th id="aclactionth' . $group->value . '">';
496 $html[] = '<span class="acl-action">' . JText::_('JLIB_RULES_CALCULATED_SETTING') . '</span>';
497 $html[] = '</th>';
498 }
499
500 $html[] = '</tr>';
501 $html[] = '</thead>';
502 $html[] = '<tbody>';
503
504 foreach ($actions as $action)
505 {
506 $html[] = '<tr>';
507 $html[] = '<td headers="actions-th' . $group->value . '">';
508 $html[] = '<label for="' . $this->id . '_' . $action->name . '_' . $group->value . '" class="hasTooltip" title="'
509 . htmlspecialchars(JText::_($action->title) . ' ' . JText::_($action->description), ENT_COMPAT, 'UTF-8') . '">';
510 $html[] = JText::_($action->title);
511 $html[] = '</label>';
512 $html[] = '</td>';
513
514 $html[] = '<td headers="settings-th' . $group->value . '">';
515
516 $html[] = '<select class="input-small" name="' . $this->name . '[' . $action->name . '][' . $group->value . ']" id="' . $this->id . '_' . $action->name
517 . '_' . $group->value . '" title="'
518 . JText::sprintf('JLIB_RULES_SELECT_ALLOW_DENY_GROUP', JText::_($action->title), trim($group->text)) . '">';
519
520 $inheritedRule = JAccess::checkGroup($group->value, $action->name, $assetId);
521
522
523 $assetRule = $assetRules->allow($action->name, $group->value);
524
525
526
527
528 $html[] = '<option value=""' . ($assetRule === null ? ' selected="selected"' : '') . '>'
529 . JText::_(empty($group->parent_id) && empty($component) ? 'JLIB_RULES_NOT_SET' : 'JLIB_RULES_INHERITED') . '</option>';
530 $html[] = '<option value="1"' . ($assetRule === true ? ' selected="selected"' : '') . '>' . JText::_('JLIB_RULES_ALLOWED')
531 . '</option>';
532 $html[] = '<option value="0"' . ($assetRule === false ? ' selected="selected"' : '') . '>' . JText::_('JLIB_RULES_DENIED')
533 . '</option>';
534
535 $html[] = '</select>  ';
536
537
538 if (($assetRule === true) && ($inheritedRule === false))
539 {
540 $html[] = JText::_('JLIB_RULES_CONFLICT');
541 }
542
543 $html[] = '</td>';
544
545
546
547 if ($canCalculateSettings)
548 {
549 $html[] = '<td headers="aclactionth' . $group->value . '">';
550
551
552
553
554 if (JAccess::checkGroup($group->value, 'core.admin', $assetId) !== true)
555 {
556 if ($inheritedRule === null)
557 {
558 $html[] = '<span class="label label-important">' . JText::_('JLIB_RULES_NOT_ALLOWED') . '</span>';
559 }
560 elseif ($inheritedRule === true)
561 {
562 $html[] = '<span class="label label-success">' . JText::_('JLIB_RULES_ALLOWED') . '</span>';
563 }
564 elseif ($inheritedRule === false)
565 {
566 if ($assetRule === false)
567 {
568 $html[] = '<span class="label label-important">' . JText::_('JLIB_RULES_NOT_ALLOWED') . '</span>';
569 }
570 else
571 {
572 $html[] = '<span class="label"><i class="icon-lock icon-white"></i> ' . JText::_('JLIB_RULES_NOT_ALLOWED_LOCKED')
573 . '</span>';
574 }
575 }
576 }
577 elseif (!empty($component))
578 {
579 $html[] = '<span class="label label-success"><i class="icon-lock icon-white"></i> ' . JText::_('JLIB_RULES_ALLOWED_ADMIN')
580 . '</span>';
581 }
582 else
583 {
584
585
586 if ($action->name === 'core.admin')
587 {
588 $html[] = '<span class="label label-success">' . JText::_('JLIB_RULES_ALLOWED') . '</span>';
589 }
590 elseif ($inheritedRule === false)
591 {
592
593 $html[] = '<span class="label label-important"><i class="icon-lock icon-white"></i> '
594 . JText::_('JLIB_RULES_NOT_ALLOWED_ADMIN_CONFLICT') . '</span>';
595 }
596 else
597 {
598 $html[] = '<span class="label label-success"><i class="icon-lock icon-white"></i> ' . JText::_('JLIB_RULES_ALLOWED_ADMIN')
599 . '</span>';
600 }
601 }
602
603 $html[] = '</td>';
604 }
605
606 $html[] = '</tr>';
607 }
608
609 $html[] = '</tbody>';
610 $html[] = '</table></div>';
611 }
612
613 $html[] = '</div></div>';
614
615 $html[] = '<div class="alert">';
616
617 if ($section == 'component' || $section == null)
618 {
619 $html[] = JText::_('JLIB_RULES_SETTING_NOTES');
620 }
621 else
622 {
623 $html[] = JText::_('JLIB_RULES_SETTING_NOTES_ITEM');
624 }
625
626 $html[] = '</div>';
627
628 return implode("\n", $html);
629 }
630 }
631