Skip to content

Commit e140052

Browse files
committed
Extended PMF_Perm_Medium::getAllGroupsOptions() to allow array of group ids
1 parent 49c4f6e commit e140052

File tree

4 files changed

+31
-28
lines changed

4 files changed

+31
-28
lines changed

phpmyfaq/admin/category.add.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,33 @@
2222
exit();
2323
}
2424
?>
25-
2625
<header>
2726
<h2><?php print $PMF_LANG['ad_categ_new']; ?></h2>
2827
</header>
29-
3028
<?php
3129
if ($permission["addcateg"]) {
3230

3331
$category = new PMF_Category($faqConfig, false);
3432
$category->setUser($currentAdminUser);
3533
$category->setGroups($currentAdminGroups);
36-
$parent_id = PMF_Filter::filterInput(INPUT_GET, 'cat', FILTER_VALIDATE_INT, 0);
34+
$parentId = PMF_Filter::filterInput(INPUT_GET, 'cat', FILTER_VALIDATE_INT, 0);
3735
?>
3836
<form class="form-horizontal" action="?action=savecategory" method="post">
3937
<input type="hidden" id="lang" name="lang" value="<?php print $LANGCODE; ?>" />
40-
<input type="hidden" name="parent_id" value="<?php print $parent_id; ?>" />
38+
<input type="hidden" name="parent_id" value="<?php print $parentId; ?>" />
4139
<input type="hidden" name="csrf" value="<?php print $user->getCsrfTokenFromSession(); ?>" />
4240
<?php
43-
if ($parent_id > 0) {
44-
$user_allowed = $category->getPermissions('user', array($parent_id));
45-
$group_allowed = $category->getPermissions('group', array($parent_id));
41+
if ($parentId > 0) {
42+
$user_allowed = $category->getPermissions('user', array($parentId));
43+
$group_allowed = $category->getPermissions('group', array($parentId));
4644
?>
4745
<input type="hidden" name="restricted_users" value="<?php print $user_allowed[0]; ?>" />
4846
<input type="hidden" name="restricted_groups" value="<?php print $group_allowed[0]; ?>" />
4947
<?php
5048
printf('<div class="control-group">%s: %s (%s)</div>',
5149
$PMF_LANG["msgMainCategory"],
52-
$category->categoryName[$parent_id]["name"],
53-
$languageCodes[PMF_String::strtoupper($category->categoryName[$parent_id]["lang"])]);
50+
$category->categoryName[$parentId]["name"],
51+
$languageCodes[PMF_String::strtoupper($category->categoryName[$parentId]["lang"])]);
5452
}
5553
?>
5654
<div class="control-group">
@@ -71,13 +69,13 @@
7169
<label class="control-label" for="user_id"><?php print $PMF_LANG["ad_categ_owner"]; ?>:</label>
7270
<div class="controls">
7371
<select name="user_id" id="user_id" size="1">
74-
<?php print $user->getAllUserOptions(1); ?>
72+
<?php print $user->getAllUserOptions(); ?>
7573
</select>
7674
</div>
7775
</div>
7876

7977
<?php
80-
if ($parent_id == 0) {
78+
if ($parentId == 0) {
8179
if ($faqConfig->get('security.permLevel') != 'basic') {
8280
?>
8381
<div class="control-group">
@@ -91,8 +89,8 @@
9189
<input type="radio" name="grouppermission" value="restricted" />
9290
<?php print $PMF_LANG['ad_entry_restricted_groups']; ?>
9391
</label>
94-
<select name="restricted_groups" size="1">
95-
<?php print $user->perm->getAllGroupsOptions(1); ?>
92+
<select name="restricted_groups" size="3" multiple>
93+
<?php print $user->perm->getAllGroupsOptions(); ?>
9694
</select>
9795
</div>
9896
</div>

phpmyfaq/admin/category.edit.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@
9696
<input type="radio" name="grouppermission" value="restricted" <?php print ($restricted_groups ? 'checked="checked"' : ''); ?>/>
9797
<?php print $PMF_LANG['ad_entry_restricted_groups']; ?>
9898
</label>
99-
<select name="restricted_groups" size="1">
100-
<?php print $user->perm->getAllGroupsOptions($group_permission[0]); ?>
99+
<select name="restricted_groups" size="3" multiple>
100+
<?php print $user->perm->getAllGroupsOptions($group_permission); ?>
101101
</select>
102102
</div>
103103
</div>

phpmyfaq/admin/record.edit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@
561561
<input type="radio" name="grouppermission" value="restricted" <?php echo ($restrictedGroups ? 'checked="checked"' : ''); ?>/>
562562
<?php echo $PMF_LANG['ad_entry_restricted_groups']; ?>
563563
<select name="restricted_groups" size="1" class="input-medium">
564-
<?php echo $user->perm->getAllGroupsOptions($groupPermission[0]); ?>
564+
<?php echo $user->perm->getAllGroupsOptions($groupPermission); ?>
565565
</select>
566566
</label>
567567
</div>

phpmyfaq/inc/Perm/Medium.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -620,21 +620,25 @@ public function getAllGroups()
620620
/**
621621
* Get all groups in <option> tags
622622
*
623-
* @param integer $groups Selected group
623+
* @param array $groups Selected groups
624+
*
624625
* @return string
625626
*/
626-
public function getAllGroupsOptions($groups = -1)
627+
public function getAllGroupsOptions(Array $groups)
627628
{
628-
$options = '';
629+
$options = '';
629630
$allGroups = $this->getAllGroups();
630-
foreach ($allGroups as $group_id) {
631-
if (-1 != $group_id) {
631+
632+
foreach ($allGroups as $groupId) {
633+
if (-1 != $groupId) {
632634
$options .= sprintf('<option value="%d"%s>%s</option>',
633-
$group_id,
634-
($group_id == $groups) ? ' selected="selected"' : '',
635-
$this->getGroupName($group_id));
635+
$groupId,
636+
(in_array($groupId, $groups) ? ' selected="selected"' : ''),
637+
$this->getGroupName($groupId)
638+
);
636639
}
637640
}
641+
638642
return $options;
639643
}
640644

@@ -874,12 +878,12 @@ public function refuseAllGroupRights($group_id)
874878
/**
875879
* Returns the name of the group $group_id.
876880
*
877-
* @param integer $group_id Group ID
881+
* @param integer $groupId Group ID
878882
* @return string
879883
*/
880-
public function getGroupName($group_id)
884+
public function getGroupName($groupId)
881885
{
882-
if ($group_id <= 0 || !is_numeric($group_id)) {
886+
if ($groupId <= 0 || !is_numeric($groupId)) {
883887
return false;
884888
}
885889

@@ -891,7 +895,8 @@ public function getGroupName($group_id)
891895
WHERE
892896
group_id = %d",
893897
PMF_Db::getTablePrefix(),
894-
$group_id);
898+
$groupId
899+
);
895900

896901
$res = $this->config->getDb()->query($select);
897902
if ($this->config->getDb()->numRows($res) != 1) {

0 commit comments

Comments
 (0)