1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Newbb; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* TODO: synchronize cascade permissions for multi-level |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Add category navigation to forum casscade structure |
11
|
|
|
* <ol>Special points: |
12
|
|
|
* <li> Use negative values for category IDs to avoid conflict between category and forum |
13
|
|
|
* <li> Disabled checkbox for categories to avoid unnecessary permission items for categories in forum permission table |
14
|
|
|
* </ol> |
15
|
|
|
* |
16
|
|
|
* Note: this is a __patchy__ solution. We should have a more extensible and flexible group permission management: not only for data architecture but also for management interface |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class GroupFormCheckBox |
21
|
|
|
* @package XoopsModules\Newbb |
22
|
|
|
*/ |
23
|
|
|
class GroupFormCheckBox extends \XoopsGroupFormCheckBox |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @param $caption |
27
|
|
|
* @param $name |
28
|
|
|
* @param $groupId |
29
|
|
|
* @param null $values |
|
|
|
|
30
|
|
|
*/ |
31
|
|
|
public function __construct($caption, $name, $groupId, $values = null) |
32
|
|
|
{ |
33
|
|
|
parent::__construct($caption, $name, $groupId, $values); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Renders checkbox options for an item tree |
38
|
|
|
* |
39
|
|
|
* @param string $tree |
40
|
|
|
* @param array $option |
41
|
|
|
* @param string $prefix |
42
|
|
|
* @param array $parentIds |
43
|
|
|
*/ |
44
|
|
|
public function _renderOptionTree(&$tree, $option, $prefix, $parentIds = []) |
45
|
|
|
{ |
46
|
|
|
if ($option['id'] > 0) { |
47
|
|
|
$tree .= $prefix . '<input type="checkbox" name="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" id="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" onclick="'; |
48
|
|
|
foreach ($parentIds as $pid) { |
49
|
|
|
if ($pid <= 0) { |
50
|
|
|
continue; |
51
|
|
|
} |
52
|
|
|
$parent_ele = $this->getName() . '[groups][' . $this->_groupId . '][' . $pid . ']'; |
53
|
|
|
$tree .= "var ele = xoopsGetElementById('" . $parent_ele . "'); if (ele.checked !== true) {ele.checked = this.checked;}"; |
54
|
|
|
} |
55
|
|
|
foreach ($option['allchild'] as $cid) { |
56
|
|
|
$child_ele = $this->getName() . '[groups][' . $this->_groupId . '][' . $cid . ']'; |
57
|
|
|
$tree .= "var ele = xoopsGetElementById('" . $child_ele . "'); if (this.checked !== true) {ele.checked = false;}"; |
58
|
|
|
} |
59
|
|
|
$tree .= '" value="1"'; |
60
|
|
|
if (\in_array($option['id'], $this->_value)) { |
61
|
|
|
$tree .= ' checked'; |
62
|
|
|
} |
63
|
|
|
$tree .= ' >' . $option['name'] . '<input type="hidden" name="' . $this->getName() . '[parents][' . $option['id'] . ']" value="' . \implode(':', $parentIds) . '" ><input type="hidden" name="' . $this->getName() . '[itemname][' . $option['id'] . ']" value="' . \htmlspecialchars( |
64
|
|
|
$option['name'], |
65
|
|
|
\ENT_QUOTES | \ENT_HTML5 |
66
|
|
|
) . "\" ><br>\n"; |
67
|
|
|
} else { |
68
|
|
|
$tree .= $prefix . $option['name'] . '<input type="hidden" id="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . "]\" ><br>\n"; |
69
|
|
|
} |
70
|
|
|
if (isset($option['children'])) { |
71
|
|
|
foreach ($option['children'] as $child) { |
72
|
|
|
if ($option['id'] > 0) { |
73
|
|
|
// array_push($parentIds, $option['id']); |
74
|
|
|
$parentIds[] = $option['id']; |
75
|
|
|
} |
76
|
|
|
$this->_renderOptionTree($tree, $this->_optionTree[$child], $prefix . ' -', $parentIds); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|