Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * | |
38 | */ | |
39 | class CRM_Core_Permission_Drupal6 extends CRM_Core_Permission_DrupalBase { | |
40 | ||
41 | /** | |
42 | * is this user someone with access for the entire system | |
43 | * | |
44 | * @var boolean | |
45 | */ | |
46 | protected $_viewAdminUser = FALSE; | |
47 | protected $_editAdminUser = FALSE; | |
48 | ||
49 | /** | |
50 | * am in in view permission or edit permission? | |
51 | * @var boolean | |
52 | */ | |
53 | protected $_viewPermission = FALSE; | |
54 | protected $_editPermission = FALSE; | |
55 | ||
56 | /** | |
57 | * the current set of permissioned groups for the user | |
58 | * | |
59 | * @var array | |
60 | */ | |
61 | protected $_viewPermissionedGroups; | |
62 | protected $_editPermissionedGroups; | |
63 | ||
64 | /** | |
65 | * Given a roles array, check for access requirements | |
66 | * | |
67 | * @param array $array the roles to check | |
68 | * | |
69 | * @return boolean true if yes, else false | |
70 | * @access public | |
71 | */ | |
72 | ||
73 | function checkGroupRole($array) { | |
74 | if (function_exists('user_load') && isset($array)) { | |
75 | $user = user_load(array('uid' => $GLOBALS['user']->uid)); | |
76 | //if giver roles found in user roles - return true | |
77 | foreach ($array as $key => $value) { | |
78 | if (in_array($value, $user->roles)) { | |
79 | return TRUE; | |
80 | } | |
81 | } | |
82 | } | |
83 | return FALSE; | |
84 | } | |
85 | ||
86 | /** | |
87 | * Get all the contact emails for users that have a specific role | |
88 | * | |
89 | * @param string $roleName name of the role we are interested in | |
90 | * | |
91 | * @return string a comma separated list of email addresses | |
92 | */ | |
93 | public function roleEmails($roleName) { | |
94 | static $_cache = array(); | |
95 | ||
96 | if (isset($_cache[$roleName])) { | |
97 | return $_cache[$roleName]; | |
98 | } | |
99 | ||
100 | $uids = array(); | |
101 | $sql = " | |
102 | SELECT {users}.uid | |
103 | FROM {users} | |
104 | LEFT JOIN {users_roles} ON {users}.uid = {users_roles}.uid | |
105 | INNER JOIN {role} ON ( {role}.rid = {users_roles}.rid OR {role}.rid = 2 ) | |
106 | WHERE {role}. name LIKE '%%{$roleName}%%' | |
107 | AND {users}.status = 1 | |
108 | "; | |
109 | ||
110 | $query = db_query($sql); | |
111 | while ($result = db_fetch_object($query)) { | |
112 | $uids[] = $result->uid; | |
113 | } | |
114 | ||
115 | $_cache[$roleName] = self::getContactEmails($uids); | |
116 | return $_cache[$roleName]; | |
117 | } | |
118 | ||
119 | /** | |
120 | * Get all the contact emails for users that have a specific permission | |
121 | * | |
122 | * @param string $permissionName name of the permission we are interested in | |
123 | * | |
124 | * @return string a comma separated list of email addresses | |
125 | */ | |
126 | public function permissionEmails($permissionName) { | |
127 | static $_cache = array(); | |
128 | ||
129 | if (isset($_cache[$permissionName])) { | |
130 | return $_cache[$permissionName]; | |
131 | } | |
132 | ||
133 | $uids = array(); | |
134 | $sql = " | |
135 | SELECT {users}.uid, {permission}.perm | |
136 | FROM {users} | |
137 | LEFT JOIN {users_roles} ON {users}.uid = {users_roles}.uid | |
138 | INNER JOIN {permission} ON ( {permission}.rid = {users_roles}.rid OR {permission}.rid = 2 ) | |
139 | WHERE {permission}.perm LIKE '%%{$permissionName}%%' | |
140 | AND {users}.status = 1 | |
141 | "; | |
142 | ||
143 | $query = db_query($sql); | |
144 | while ($result = db_fetch_object($query)) { | |
145 | $uids[] = $result->uid; | |
146 | } | |
147 | ||
148 | $_cache[$permissionName] = self::getContactEmails($uids); | |
149 | return $_cache[$permissionName]; | |
150 | } | |
151 | ||
152 | /** | |
153 | * Remove all vestiges of permissions for the given module. | |
154 | * | |
155 | * Does nothing in Drupal 6. | |
156 | */ | |
157 | function uninstallPermissions($module) { | |
158 | } | |
159 | ||
160 | /** | |
c4bc14ed | 161 | * {@inheritdoc} |
6a488035 TO |
162 | * |
163 | * Does nothing in Drupal 6. | |
164 | */ | |
0d8fc497 | 165 | function upgradePermissions($permissions) { |
6a488035 TO |
166 | } |
167 | ||
168 | /** | |
169 | * Get the permissions defined in the hook_civicrm_permission implementation | |
170 | * of the given module. | |
171 | * | |
172 | * @return Array of permissions, in the same format as CRM_Core_Permission::getCorePermissions(). | |
173 | */ | |
174 | static function getModulePermissions($module) { | |
175 | $return_permissions = array(); | |
176 | $fn_name = "{$module}_civicrm_permission"; | |
177 | if (function_exists($fn_name)) { | |
178 | $fn_name($return_permissions); | |
179 | } | |
180 | return $return_permissions; | |
181 | } | |
182 | } | |
183 |