5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
33 * @copyright CiviCRM LLC (c) 2004-2013
40 * The various type of permissions
52 * given a permission string, check for access requirements
54 * @param string $str the permission to check
55 * @param int $contactID the contactID for whom the check is made
57 * @return boolean true if yes, else false
61 static function check($str, $contactID = NULL) {
62 if ($contactID == NULL) {
63 $session = CRM_Core_Session
::singleton();
64 $contactID = $session->get('userID');
72 return CRM_ACL_BAO_ACL
::check($str, $contactID);
76 * Get the permissioned where clause for the user
78 * @param int $type the type of permission needed
79 * @param array $tables (reference ) add the tables that are needed for the select clause
80 * @param array $whereTables (reference ) add the tables that are needed for the where clause
81 * @param int $contactID the contactID for whom the check is made
82 * @param bool $onlyDeleted whether to include only deleted contacts
83 * @param bool $skipDeleteClause don't add delete clause if this is true,
84 * this means it is handled by generating query
86 * @return string the group where clause for this user
89 public static function whereClause($type,
94 $skipDeleteClause = FALSE
96 // the default value which is valid for rhe final AND
97 $deleteClause = ' ( 1 ) ';
98 if (!$skipDeleteClause) {
99 if (CRM_Core_Permission
::check('access deleted contacts') and $onlyDeleted) {
100 $deleteClause = '(contact_a.is_deleted)';
104 $deleteClause = '(contact_a.is_deleted = 0)';
108 // first see if the contact has edit / view all contacts
109 if (CRM_Core_Permission
::check('edit all contacts') ||
110 ($type == self
::VIEW
&&
111 CRM_Core_Permission
::check('view all contacts')
114 return $skipDeleteClause ?
' ( 1 ) ' : $deleteClause;
117 if ($contactID == NULL) {
118 $session = CRM_Core_Session
::singleton();
119 $contactID = $session->get('userID');
127 return implode(' AND ',
129 CRM_ACL_BAO_ACL
::whereClause($type,
140 * get all the groups the user has access to for the given operation
142 * @param int $type the type of permission needed
143 * @param int $contactID the contactID for whom the check is made
145 * @return array the ids of the groups for which the user has permissions
148 public static function group(
151 $tableName = 'civicrm_saved_search',
153 $includedGroups = NULL
155 if ($contactID == NULL) {
156 $session = CRM_Core_Session
::singleton();
157 $contactID = $session->get('userID');
165 return CRM_ACL_BAO_ACL
::group($type, $contactID, $tableName, $allGroups, $includedGroups);
169 * check if the user has access to this group for operation $type
171 * @param int $type the type of permission needed
172 * @param int $contactID the contactID for whom the check is made
174 * @return array the ids of the groups for which the user has permissions
177 public static function groupPermission(
181 $tableName = 'civicrm_saved_search',
183 $includedGroups = NULL
185 static $cache = array();
188 $session = CRM_Core_Session
::singleton();
190 if ($session->get('userID')) {
191 $contactID = $session->get('userID');
195 $key = "{$tableName}_{$type}_{$contactID}";
196 if (array_key_exists($key, $cache)) {
197 $groups = &$cache[$key];
200 $groups = self
::group($type, $contactID, $tableName, $allGroups, $includedGroups);
201 $cache[$key] = $groups;
204 return in_array($groupID, $groups) ?
TRUE : FALSE;