3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 class CRM_Core_Permission_Drupal6
extends CRM_Core_Permission_DrupalBase
{
24 * Is this user someone with access for the entire system.
28 protected $_viewAdminUser = FALSE;
29 protected $_editAdminUser = FALSE;
32 * Am in in view permission or edit permission?
35 protected $_viewPermission = FALSE;
36 protected $_editPermission = FALSE;
39 * The current set of permissioned groups for the user.
43 protected $_viewPermissionedGroups;
44 protected $_editPermissionedGroups;
47 * Given a permission string, check for access requirements
50 * The permission to check.
55 * true if yes, else false
57 public function check($str, $userId = NULL) {
58 $str = $this->translatePermission($str, 'Drupal6', [
59 'view user account' => 'access user profiles',
60 'administer users' => 'administer users',
62 if ($str == CRM_Core_Permission
::ALWAYS_DENY_PERMISSION
) {
65 if ($str == CRM_Core_Permission
::ALWAYS_ALLOW_PERMISSION
) {
68 if (function_exists('user_access')) {
71 $account = user_load($userId);
73 return user_access($str, $account);
79 * Given a roles array, check for access requirements
85 * true if yes, else false
87 public function checkGroupRole($array) {
88 if (function_exists('user_load') && isset($array)) {
89 $user = user_load(['uid' => $GLOBALS['user']->uid
]);
90 //if giver roles found in user roles - return true
91 foreach ($array as $key => $value) {
92 if (in_array($value, $user->roles
)) {
101 * Get all the contact emails for users that have a specific role.
103 * @param string $roleName
104 * Name of the role we are interested in.
107 * a comma separated list of email addresses
109 public function roleEmails($roleName) {
112 if (isset($_cache[$roleName])) {
113 return $_cache[$roleName];
120 LEFT JOIN {users_roles} ON {users}.uid = {users_roles}.uid
121 INNER JOIN {role} ON ( {role}.rid = {users_roles}.rid OR {role}.rid = 2 )
122 WHERE {role}. name LIKE '%%{$roleName}%%'
123 AND {users}.status = 1
126 $query = db_query($sql);
127 while ($result = db_fetch_object($query)) {
128 $uids[] = $result->uid
;
131 $_cache[$roleName] = self
::getContactEmails($uids);
132 return $_cache[$roleName];
136 * Get all the contact emails for users that have a specific permission.
138 * @param string $permissionName
139 * Name of the permission we are interested in.
142 * a comma separated list of email addresses
144 public function permissionEmails($permissionName) {
147 if (isset($_cache[$permissionName])) {
148 return $_cache[$permissionName];
153 SELECT {users}.uid, {permission}.perm
155 LEFT JOIN {users_roles} ON {users}.uid = {users_roles}.uid
156 INNER JOIN {permission} ON ( {permission}.rid = {users_roles}.rid OR {permission}.rid = 2 )
157 WHERE {permission}.perm LIKE '%%{$permissionName}%%'
158 AND {users}.status = 1
161 $query = db_query($sql);
162 while ($result = db_fetch_object($query)) {
163 $uids[] = $result->uid
;
166 $_cache[$permissionName] = self
::getContactEmails($uids);
167 return $_cache[$permissionName];
173 public function isModulePermissionSupported() {
180 * Does nothing in Drupal 6.
182 public function upgradePermissions($permissions) {
183 // D6 allows us to be really lazy... things get cleaned up when the admin form is next submitted...
187 * Get the permissions defined in the hook_civicrm_permission implementation
188 * of the given module.
193 * Array of permissions, in the same format as CRM_Core_Permission::getCorePermissions().
195 public function getModulePermissions($module):array {
196 $return_permissions = [];
197 $fn_name = "{$module}_civicrm_permission";
198 if (function_exists($fn_name)) {
199 $fn_name($return_permissions);
201 return $return_permissions;