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
23 class CRM_Core_Permission_Drupal6
extends CRM_Core_Permission_DrupalBase
{
26 * Is this user someone with access for the entire system.
30 protected $_viewAdminUser = FALSE;
31 protected $_editAdminUser = FALSE;
34 * Am in in view permission or edit permission?
37 protected $_viewPermission = FALSE;
38 protected $_editPermission = FALSE;
41 * The current set of permissioned groups for the user.
45 protected $_viewPermissionedGroups;
46 protected $_editPermissionedGroups;
49 * Given a permission string, check for access requirements
52 * The permission to check.
57 * true if yes, else false
59 public function check($str, $userId = NULL) {
60 $str = $this->translatePermission($str, 'Drupal6', [
61 'view user account' => 'access user profiles',
62 'administer users' => 'administer users',
64 if ($str == CRM_Core_Permission
::ALWAYS_DENY_PERMISSION
) {
67 if ($str == CRM_Core_Permission
::ALWAYS_ALLOW_PERMISSION
) {
70 if (function_exists('user_access')) {
73 $account = user_load($userId);
75 return user_access($str, $account);
81 * Given a roles array, check for access requirements
87 * true if yes, else false
89 public function checkGroupRole($array) {
90 if (function_exists('user_load') && isset($array)) {
91 $user = user_load(['uid' => $GLOBALS['user']->uid
]);
92 //if giver roles found in user roles - return true
93 foreach ($array as $key => $value) {
94 if (in_array($value, $user->roles
)) {
103 * Get all the contact emails for users that have a specific role.
105 * @param string $roleName
106 * Name of the role we are interested in.
109 * a comma separated list of email addresses
111 public function roleEmails($roleName) {
114 if (isset($_cache[$roleName])) {
115 return $_cache[$roleName];
122 LEFT JOIN {users_roles} ON {users}.uid = {users_roles}.uid
123 INNER JOIN {role} ON ( {role}.rid = {users_roles}.rid OR {role}.rid = 2 )
124 WHERE {role}. name LIKE '%%{$roleName}%%'
125 AND {users}.status = 1
128 $query = db_query($sql);
129 while ($result = db_fetch_object($query)) {
130 $uids[] = $result->uid
;
133 $_cache[$roleName] = self
::getContactEmails($uids);
134 return $_cache[$roleName];
138 * Get all the contact emails for users that have a specific permission.
140 * @param string $permissionName
141 * Name of the permission we are interested in.
144 * a comma separated list of email addresses
146 public function permissionEmails($permissionName) {
149 if (isset($_cache[$permissionName])) {
150 return $_cache[$permissionName];
155 SELECT {users}.uid, {permission}.perm
157 LEFT JOIN {users_roles} ON {users}.uid = {users_roles}.uid
158 INNER JOIN {permission} ON ( {permission}.rid = {users_roles}.rid OR {permission}.rid = 2 )
159 WHERE {permission}.perm LIKE '%%{$permissionName}%%'
160 AND {users}.status = 1
163 $query = db_query($sql);
164 while ($result = db_fetch_object($query)) {
165 $uids[] = $result->uid
;
168 $_cache[$permissionName] = self
::getContactEmails($uids);
169 return $_cache[$permissionName];
175 public function isModulePermissionSupported() {
182 * Does nothing in Drupal 6.
184 public function upgradePermissions($permissions) {
185 // D6 allows us to be really lazy... things get cleaned up when the admin form is next submitted...
189 * Get the permissions defined in the hook_civicrm_permission implementation
190 * of the given module.
195 * Array of permissions, in the same format as CRM_Core_Permission::getCorePermissions().
197 public static function getModulePermissions($module) {
198 $return_permissions = [];
199 $fn_name = "{$module}_civicrm_permission";
200 if (function_exists($fn_name)) {
201 $fn_name($return_permissions);
203 return $return_permissions;