3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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
67 * @param string $str the permission to check
69 * @param int $contactID
71 * @return boolean true if yes, else false
73 public function check($str, $contactID = NULL) {
74 $str = $this->translatePermission($str, 'Drupal6', array(
75 'view user account' => 'access user profiles',
76 'administer users' => 'administer users',
78 if ($str == CRM_Core_Permission
::ALWAYS_DENY_PERMISSION
) {
81 if ($str == CRM_Core_Permission
::ALWAYS_ALLOW_PERMISSION
) {
84 if (function_exists('user_access')) {
85 return user_access($str) ?
TRUE : FALSE;
91 * Given a roles array, check for access requirements
93 * @param array $array the roles to check
95 * @return boolean true if yes, else false
98 public function checkGroupRole($array) {
99 if (function_exists('user_load') && isset($array)) {
100 $user = user_load(array('uid' => $GLOBALS['user']->uid
));
101 //if giver roles found in user roles - return true
102 foreach ($array as $key => $value) {
103 if (in_array($value, $user->roles
)) {
112 * Get all the contact emails for users that have a specific role
114 * @param string $roleName name of the role we are interested in
116 * @return string a comma separated list of email addresses
118 public function roleEmails($roleName) {
119 static $_cache = array();
121 if (isset($_cache[$roleName])) {
122 return $_cache[$roleName];
129 LEFT JOIN {users_roles} ON {users}.uid = {users_roles}.uid
130 INNER JOIN {role} ON ( {role}.rid = {users_roles}.rid OR {role}.rid = 2 )
131 WHERE {role}. name LIKE '%%{$roleName}%%'
132 AND {users}.status = 1
135 $query = db_query($sql);
136 while ($result = db_fetch_object($query)) {
137 $uids[] = $result->uid
;
140 $_cache[$roleName] = self
::getContactEmails($uids);
141 return $_cache[$roleName];
145 * Get all the contact emails for users that have a specific permission
147 * @param string $permissionName name of the permission we are interested in
149 * @return string a comma separated list of email addresses
151 public function permissionEmails($permissionName) {
152 static $_cache = array();
154 if (isset($_cache[$permissionName])) {
155 return $_cache[$permissionName];
160 SELECT {users}.uid, {permission}.perm
162 LEFT JOIN {users_roles} ON {users}.uid = {users_roles}.uid
163 INNER JOIN {permission} ON ( {permission}.rid = {users_roles}.rid OR {permission}.rid = 2 )
164 WHERE {permission}.perm LIKE '%%{$permissionName}%%'
165 AND {users}.status = 1
168 $query = db_query($sql);
169 while ($result = db_fetch_object($query)) {
170 $uids[] = $result->uid
;
173 $_cache[$permissionName] = self
::getContactEmails($uids);
174 return $_cache[$permissionName];
180 public function isModulePermissionSupported() {
187 * Does nothing in Drupal 6.
189 public function upgradePermissions($permissions) {
190 // D6 allows us to be really lazy... things get cleaned up when the admin form is next submitted...
194 * Get the permissions defined in the hook_civicrm_permission implementation
195 * of the given module.
199 * @return Array of permissions, in the same format as CRM_Core_Permission::getCorePermissions().
201 public static function getModulePermissions($module) {
202 $return_permissions = array();
203 $fn_name = "{$module}_civicrm_permission";
204 if (function_exists($fn_name)) {
205 $fn_name($return_permissions);
207 return $return_permissions;