3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2017
39 class CRM_Core_Permission_Drupal6
extends CRM_Core_Permission_DrupalBase
{
42 * Is this user someone with access for the entire system.
46 protected $_viewAdminUser = FALSE;
47 protected $_editAdminUser = FALSE;
50 * Am in in view permission or edit permission?
53 protected $_viewPermission = FALSE;
54 protected $_editPermission = FALSE;
57 * The current set of permissioned groups for the user.
61 protected $_viewPermissionedGroups;
62 protected $_editPermissionedGroups;
65 * Given a permission string, check for access requirements
68 * The permission to check.
70 * @param int $contactID
73 * true if yes, else false
75 public function check($str, $contactID = NULL) {
76 $str = $this->translatePermission($str, 'Drupal6', array(
77 'view user account' => 'access user profiles',
78 'administer users' => 'administer users',
80 if ($str == CRM_Core_Permission
::ALWAYS_DENY_PERMISSION
) {
83 if ($str == CRM_Core_Permission
::ALWAYS_ALLOW_PERMISSION
) {
86 if (function_exists('user_access')) {
87 return user_access($str) ?
TRUE : FALSE;
93 * Given a roles array, check for access requirements
99 * true if yes, else false
101 public function checkGroupRole($array) {
102 if (function_exists('user_load') && isset($array)) {
103 $user = user_load(array('uid' => $GLOBALS['user']->uid
));
104 //if giver roles found in user roles - return true
105 foreach ($array as $key => $value) {
106 if (in_array($value, $user->roles
)) {
115 * Get all the contact emails for users that have a specific role.
117 * @param string $roleName
118 * Name of the role we are interested in.
121 * a comma separated list of email addresses
123 public function roleEmails($roleName) {
124 static $_cache = array();
126 if (isset($_cache[$roleName])) {
127 return $_cache[$roleName];
134 LEFT JOIN {users_roles} ON {users}.uid = {users_roles}.uid
135 INNER JOIN {role} ON ( {role}.rid = {users_roles}.rid OR {role}.rid = 2 )
136 WHERE {role}. name LIKE '%%{$roleName}%%'
137 AND {users}.status = 1
140 $query = db_query($sql);
141 while ($result = db_fetch_object($query)) {
142 $uids[] = $result->uid
;
145 $_cache[$roleName] = self
::getContactEmails($uids);
146 return $_cache[$roleName];
150 * Get all the contact emails for users that have a specific permission.
152 * @param string $permissionName
153 * Name of the permission we are interested in.
156 * a comma separated list of email addresses
158 public function permissionEmails($permissionName) {
159 static $_cache = array();
161 if (isset($_cache[$permissionName])) {
162 return $_cache[$permissionName];
167 SELECT {users}.uid, {permission}.perm
169 LEFT JOIN {users_roles} ON {users}.uid = {users_roles}.uid
170 INNER JOIN {permission} ON ( {permission}.rid = {users_roles}.rid OR {permission}.rid = 2 )
171 WHERE {permission}.perm LIKE '%%{$permissionName}%%'
172 AND {users}.status = 1
175 $query = db_query($sql);
176 while ($result = db_fetch_object($query)) {
177 $uids[] = $result->uid
;
180 $_cache[$permissionName] = self
::getContactEmails($uids);
181 return $_cache[$permissionName];
187 public function isModulePermissionSupported() {
194 * Does nothing in Drupal 6.
196 public function upgradePermissions($permissions) {
197 // D6 allows us to be really lazy... things get cleaned up when the admin form is next submitted...
201 * Get the permissions defined in the hook_civicrm_permission implementation
202 * of the given module.
207 * Array of permissions, in the same format as CRM_Core_Permission::getCorePermissions().
209 public static function getModulePermissions($module) {
210 $return_permissions = array();
211 $fn_name = "{$module}_civicrm_permission";
212 if (function_exists($fn_name)) {
213 $fn_name($return_permissions);
215 return $return_permissions;