3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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 null $contactID
71 * @return boolean true if yes, else false
74 function check($str, $contactID = NULL) {
75 $str = $this->translatePermission($str, 'Drupal6', array(
76 'view user account' => 'access user profiles',
77 'administer users' => 'administer users',
79 if ($str == CRM_Core_Permission
::ALWAYS_DENY_PERMISSION
) {
82 if ($str == CRM_Core_Permission
::ALWAYS_ALLOW_PERMISSION
) {
85 if (function_exists('user_access')) {
86 return user_access($str) ?
TRUE : FALSE;
92 * Given a roles array, check for access requirements
94 * @param array $array the roles to check
96 * @return boolean true if yes, else false
100 function checkGroupRole($array) {
101 if (function_exists('user_load') && isset($array)) {
102 $user = user_load(array('uid' => $GLOBALS['user']->uid
));
103 //if giver roles found in user roles - return true
104 foreach ($array as $key => $value) {
105 if (in_array($value, $user->roles
)) {
114 * Get all the contact emails for users that have a specific role
116 * @param string $roleName name of the role we are interested in
118 * @return string a comma separated list of email addresses
120 public function roleEmails($roleName) {
121 static $_cache = array();
123 if (isset($_cache[$roleName])) {
124 return $_cache[$roleName];
131 LEFT JOIN {users_roles} ON {users}.uid = {users_roles}.uid
132 INNER JOIN {role} ON ( {role}.rid = {users_roles}.rid OR {role}.rid = 2 )
133 WHERE {role}. name LIKE '%%{$roleName}%%'
134 AND {users}.status = 1
137 $query = db_query($sql);
138 while ($result = db_fetch_object($query)) {
139 $uids[] = $result->uid
;
142 $_cache[$roleName] = self
::getContactEmails($uids);
143 return $_cache[$roleName];
147 * Get all the contact emails for users that have a specific permission
149 * @param string $permissionName name of the permission we are interested in
151 * @return string a comma separated list of email addresses
153 public function permissionEmails($permissionName) {
154 static $_cache = array();
156 if (isset($_cache[$permissionName])) {
157 return $_cache[$permissionName];
162 SELECT {users}.uid, {permission}.perm
164 LEFT JOIN {users_roles} ON {users}.uid = {users_roles}.uid
165 INNER JOIN {permission} ON ( {permission}.rid = {users_roles}.rid OR {permission}.rid = 2 )
166 WHERE {permission}.perm LIKE '%%{$permissionName}%%'
167 AND {users}.status = 1
170 $query = db_query($sql);
171 while ($result = db_fetch_object($query)) {
172 $uids[] = $result->uid
;
175 $_cache[$permissionName] = self
::getContactEmails($uids);
176 return $_cache[$permissionName];
182 public function isModulePermissionSupported() {
189 * Does nothing in Drupal 6.
191 function upgradePermissions($permissions) {
192 // D6 allows us to be really lazy... things get cleaned up when the admin form is next submitted...
196 * Get the permissions defined in the hook_civicrm_permission implementation
197 * of the given module.
201 * @return Array of permissions, in the same format as CRM_Core_Permission::getCorePermissions().
203 static function getModulePermissions($module) {
204 $return_permissions = array();
205 $fn_name = "{$module}_civicrm_permission";
206 if (function_exists($fn_name)) {
207 $fn_name($return_permissions);
209 return $return_permissions;