public static function modulePermission($mod, PHPWS_Group $group) { $file = PHPWS_SOURCE_DIR . 'mod/' . $mod['title'] . '/boost/permission.php'; if (!is_file($file)) { return FALSE; } $template = NULL; if ($file == FALSE) { return $file; } include $file; if (!isset($use_permissions) || $use_permissions == FALSE) { return; } $labels[] = NO_PERM_NAME; $button[] = NO_PERMISSION; if (isset($item_permissions) && $item_permissions == TRUE) { $labels[] = PART_PERM_NAME; $button[] = RESTRICTED_PERMISSION; } $labels[] = FULL_PERM_NAME; $button[] = UNRESTRICTED_PERMISSION; $permCheck = $group->getPermissionLevel($mod['title']); $form = new PHPWS_Form(); $name = 'module_permission[' . $mod['title'] . ']'; $form->addRadio($name, $button); $form->setLabel($name, $labels); $form->setMatch($name, $permCheck); $radio = $form->get($name, TRUE); foreach ($radio['elements'] as $key => $val) { $template['PERMISSION_' . $key] = $val . $radio['labels'][$key]; } if (isset($permissions)) { foreach ($permissions as $permName => $permProper) { $form = new PHPWS_Form(); $name = 'sub_permission[' . $mod['title'] . '][' . $permName . ']'; $form->addCheckBox($name, 1); if ($group->allow($mod['title'], $permName)) { $subcheck = 1; } else { $subcheck = 0; } $form->setMatch($name, $subcheck); $form->setLabel($name, $permProper); $tags = $form->get($name, TRUE); $subpermissions[] = $tags['elements'][0] . ' ' . $tags['labels'][0]; } $template['SUBPERMISSIONS'] = implode('<br />', $subpermissions); } $template['MODULE_NAME'] = $mod['proper_name']; return $template; }
/** * Although called via Current_User, this functions gives * a group with edit permissions the right to edit this item. */ public static function giveItemPermission($user_id, Key $key) { $user = new PHPWS_User($user_id); $groups = $user->getGroups(); if (empty($groups) || !is_array($groups)) { return; } if (empty($key->_edit_groups)) { $key->_edit_groups = array(); } PHPWS_Core::initModClass('users', 'Group.php'); foreach ($groups as $group_id) { $group_obj = new PHPWS_Group($group_id, false); if (!in_array($group_id, $key->_edit_groups) && $group_obj->allow($key->module, $key->edit_permission)) { $key->_edit_groups[] = $group_id; } } return $key->savePermissions(); }