예제 #1
0
 /**
  * Get all groups from database, filtered by permissions
  * for this user
  *
  * @access public
  * @static
  *
  * @return array - array reference of all groups.
  *
  */
 function &group()
 {
     if (!isset($GLOBALS['_CRM_CORE_PERMISSION_DRUPAL']['_viewPermissionedGroups'])) {
         $GLOBALS['_CRM_CORE_PERMISSION_DRUPAL']['_viewPermissionedGroups'] = $GLOBALS['_CRM_CORE_PERMISSION_DRUPAL']['_editPermissionedGroups'] = array();
         $groups =& CRM_Core_PseudoConstant::allGroup();
         if (CRM_Utils_System::checkPermission('edit all contacts')) {
             // this is the most powerful permission, so we return
             // immediately rather than dilute it further
             $GLOBALS['_CRM_CORE_PERMISSION_DRUPAL']['_editAdminUser'] = $GLOBALS['_CRM_CORE_PERMISSION_DRUPAL']['_viewAdminUser'] = true;
             $GLOBALS['_CRM_CORE_PERMISSION_DRUPAL']['_editPermission'] = $GLOBALS['_CRM_CORE_PERMISSION_DRUPAL']['_viewPermission'] = true;
             $GLOBALS['_CRM_CORE_PERMISSION_DRUPAL']['_editPermissionedGroups'] = $groups;
             $GLOBALS['_CRM_CORE_PERMISSION_DRUPAL']['_viewPermissionedGroups'] = $groups;
             return $GLOBALS['_CRM_CORE_PERMISSION_DRUPAL']['_viewPermissionedGroups'];
         } else {
             if (CRM_Utils_System::checkPermission('view all contacts')) {
                 $GLOBALS['_CRM_CORE_PERMISSION_DRUPAL']['_viewAdminUser'] = true;
                 $GLOBALS['_CRM_CORE_PERMISSION_DRUPAL']['_viewPermission'] = true;
                 $GLOBALS['_CRM_CORE_PERMISSION_DRUPAL']['_viewPermissionedGroups'] = $groups;
             }
         }
         foreach ($groups as $id => $title) {
             if (CRM_Utils_System::checkPermission(CRM_CORE_PERMISSION_EDIT_GROUPS . $title)) {
                 $GLOBALS['_CRM_CORE_PERMISSION_DRUPAL']['_editPermissionedGroups'][$id] = $title;
                 $GLOBALS['_CRM_CORE_PERMISSION_DRUPAL']['_viewPermissionedGroups'][$id] = $title;
                 $GLOBALS['_CRM_CORE_PERMISSION_DRUPAL']['_editPermission'] = true;
             } else {
                 if (CRM_Utils_System::checkPermission(CRM_CORE_PERMISSION_VIEW_GROUPS . $title)) {
                     $GLOBALS['_CRM_CORE_PERMISSION_DRUPAL']['_viewPermissionedGroups'][$id] = $title;
                     $GLOBALS['_CRM_CORE_PERMISSION_DRUPAL']['_viewPermission'] = true;
                 }
             }
         }
     }
     return $GLOBALS['_CRM_CORE_PERMISSION_DRUPAL']['_viewPermissionedGroups'];
 }
 /**
  * Get all groups from database, filtered by permissions
  * for this user
  *
  * @param string $groupType     type of group(Access/Mailing)
  * @param boolen $excludeHidden exclude hidden groups.
  *
  * @access public
  * @static
  *
  * @return array - array reference of all groups.
  *
  */
 public static function &group($groupType = NULL, $excludeHidden = TRUE)
 {
     if (!isset(self::$_viewPermissionedGroups)) {
         self::$_viewPermissionedGroups = self::$_editPermissionedGroups = array();
         $groups =& CRM_Core_PseudoConstant::allGroup($groupType, $excludeHidden);
         if (self::check('edit all contacts')) {
             // this is the most powerful permission, so we return
             // immediately rather than dilute it further
             self::$_editAdminUser = self::$_viewAdminUser = TRUE;
             self::$_editPermission = self::$_viewPermission = TRUE;
             self::$_editPermissionedGroups = $groups;
             self::$_viewPermissionedGroups = $groups;
             return self::$_viewPermissionedGroups;
         } elseif (self::check('view all contacts')) {
             self::$_viewAdminUser = TRUE;
             self::$_viewPermission = TRUE;
             self::$_viewPermissionedGroups = $groups;
         }
         $ids = CRM_ACL_API::group(CRM_Core_Permission::VIEW, NULL, 'civicrm_saved_search', $groups);
         foreach (array_values($ids) as $id) {
             $title = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $id, 'title');
             self::$_viewPermissionedGroups[$id] = $title;
             self::$_viewPermission = TRUE;
         }
         $ids = CRM_ACL_API::group(CRM_Core_Permission::EDIT, NULL, 'civicrm_saved_search', $groups);
         foreach (array_values($ids) as $id) {
             $title = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $id, 'title');
             self::$_editPermissionedGroups[$id] = $title;
             self::$_viewPermissionedGroups[$id] = $title;
             self::$_editPermission = TRUE;
             self::$_viewPermission = TRUE;
         }
     }
     return self::$_viewPermissionedGroups;
 }
예제 #3
0
 function buildForm(&$form)
 {
     $groups = array('' => ts('- select group -')) + CRM_Core_PseudoConstant::allGroup();
     $form->addElement('select', 'group_id', ts('Group'), $groups);
     /**
      * if you are using the standard template, this array tells the template what elements
      * are part of the search criteria
      */
     $form->assign('elements', array('group_id'));
 }
예제 #4
0
 /**
  * This function is to build form elements
  * params object $form object of the form
  *
  * @param Object $form      the form object that we are operating on
  * @param int    $contactId contact id
  * @param int   $type     what components are we interested in 
  * 
  * @static
  * @access public
  */
 function buildGroupTagBlock(&$form, $contactId = 0, $type = CRM_CONTACT_FORM_GROUPTAG_ALL, $visibility = false, $isRequired = null, $groupName = 'Groups(s)', $tagName = 'Tag(s)')
 {
     $type = (int) $type;
     if ($type & CRM_CONTACT_FORM_GROUPTAG_GROUP) {
         $elements = array();
         if ($visibility) {
             $group =& CRM_Core_PseudoConstant::allGroup();
         } else {
             $group =& CRM_Core_PseudoConstant::group();
         }
         foreach ($group as $id => $name) {
             if ($visibility) {
                 // make sure that this group has public visibility. not very efficient
                 $dao =& new CRM_Contact_DAO_Group();
                 $dao->id = $id;
                 if ($dao->find(true)) {
                     if ($dao->visibility == 'User and User Admin Only') {
                         continue;
                     }
                 } else {
                     continue;
                 }
             }
             $elements[] =& HTML_QuickForm::createElement('checkbox', $id, null, $name);
         }
         if (!empty($elements)) {
             $form->addGroup($elements, 'group', $groupName, '<br />');
             if ($isRequired) {
                 $form->addRule('group', ts('%1 is a required field.', array(1 => $groupName)), 'required');
             }
         }
     }
     if ($type & CRM_CONTACT_FORM_GROUPTAG_TAG) {
         $elements = array();
         $tag =& CRM_Core_PseudoConstant::tag();
         foreach ($tag as $id => $name) {
             $elements[] =& HTML_QuickForm::createElement('checkbox', $id, null, $name);
         }
         if (!empty($elements)) {
             $form->addGroup($elements, 'tag', $tagName, '<br />');
         }
         if ($isRequired) {
             $form->addRule('tag', ts('%1 is a required field.', array(1 => $tagName)), 'required');
         }
     }
 }
예제 #5
0
 /**
  * Get all groups from database, filtered by permissions
  * for this user
  *
  * @param string $groupType
  *   Type of group(Access/Mailing).
  * @param bool $excludeHidden
  *   Exclude hidden groups.
  *
  *
  * @return array
  *   array reference of all groups.
  */
 public function group($groupType = NULL, $excludeHidden = TRUE)
 {
     if (!isset($this->_viewPermissionedGroups)) {
         $this->_viewPermissionedGroups = $this->_editPermissionedGroups = array();
     }
     $groupKey = $groupType ? $groupType : 'all';
     if (!isset($this->_viewPermissionedGroups[$groupKey])) {
         $this->_viewPermissionedGroups[$groupKey] = $this->_editPermissionedGroups[$groupKey] = array();
         $groups = CRM_Core_PseudoConstant::allGroup($groupType, $excludeHidden);
         if ($this->check('edit all contacts')) {
             // this is the most powerful permission, so we return
             // immediately rather than dilute it further
             $this->_editAdminUser = $this->_viewAdminUser = TRUE;
             $this->_editPermission = $this->_viewPermission = TRUE;
             $this->_editPermissionedGroups[$groupKey] = $groups;
             $this->_viewPermissionedGroups[$groupKey] = $groups;
             return $this->_viewPermissionedGroups[$groupKey];
         } elseif ($this->check('view all contacts')) {
             $this->_viewAdminUser = TRUE;
             $this->_viewPermission = TRUE;
             $this->_viewPermissionedGroups[$groupKey] = $groups;
         }
         $ids = CRM_ACL_API::group(CRM_Core_Permission::VIEW, NULL, 'civicrm_saved_search', $groups);
         if (!empty($ids)) {
             foreach (array_values($ids) as $id) {
                 $title = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $id, 'title');
                 $this->_viewPermissionedGroups[$groupKey][$id] = $title;
                 $this->_viewPermission = TRUE;
             }
         }
         $ids = CRM_ACL_API::group(CRM_Core_Permission::EDIT, NULL, 'civicrm_saved_search', $groups);
         if (!empty($ids)) {
             foreach (array_values($ids) as $id) {
                 $title = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $id, 'title');
                 $this->_editPermissionedGroups[$groupKey][$id] = $title;
                 $this->_viewPermissionedGroups[$groupKey][$id] = $title;
                 $this->_editPermission = TRUE;
                 $this->_viewPermission = TRUE;
             }
         }
     }
     return $this->_viewPermissionedGroups[$groupKey];
 }
예제 #6
0
파일: Group.php 프로젝트: ksecor/civicrm
 /**
  * make sure that the user has permission to access this group
  *
  * @param int $id   the id of the object
  * @param int $name the name or title of the object
  *
  * @return string   the permission that the user has (or null)
  * @access public
  * @static
  */
 static function checkPermission($id, $title)
 {
     require_once 'CRM/ACL/API.php';
     require_once 'CRM/Core/Permission.php';
     $allGroups = CRM_Core_PseudoConstant::allGroup();
     $permissions = null;
     if (CRM_Core_Permission::check('edit all contacts') || CRM_ACL_API::groupPermission(CRM_ACL_API::EDIT, $id, null, 'civicrm_saved_search', $allGroups)) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('view all contacts') || CRM_ACL_API::groupPermission(CRM_ACL_API::VIEW, $id, null, 'civicrm_saved_search', $allGroups)) {
         $permissions[] = CRM_Core_Permission::VIEW;
     }
     if (CRM_Core_Permission::check('delete contacts')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     return $permissions;
 }
예제 #7
0
 /**
  * wrapper for ajax group selector.
  *
  * @param array $params
  *   Associated array for params record id.
  *
  * @return array
  *   associated array of group list
  *   -rp = rowcount
  *   -page= offset
  * @todo there seems little reason for the small number of functions that call this to pass in
  * params that then need to be translated in this function since they are coding them when calling
  */
 public static function getGroupListSelector(&$params)
 {
     // format the params
     $params['offset'] = ($params['page'] - 1) * $params['rp'];
     $params['rowCount'] = $params['rp'];
     $params['sort'] = CRM_Utils_Array::value('sortBy', $params);
     // get groups
     $groups = CRM_Contact_BAO_Group::getGroupList($params);
     //skip total if we are making call to show only children
     if (empty($params['parent_id'])) {
         // add total
         $params['total'] = CRM_Contact_BAO_Group::getGroupCount($params);
         // get all the groups
         $allGroups = CRM_Core_PseudoConstant::allGroup();
     }
     // format params and add links
     $groupList = array();
     if (!empty($groups)) {
         foreach ($groups as $id => $value) {
             $groupList[$id]['group_id'] = $value['id'];
             $groupList[$id]['count'] = $value['count'];
             $groupList[$id]['group_name'] = $value['title'];
             // append parent names if in search mode
             if (empty($params['parent_id']) && !empty($value['parents'])) {
                 $groupIds = explode(',', $value['parents']);
                 $title = array();
                 foreach ($groupIds as $gId) {
                     $title[] = $allGroups[$gId];
                 }
                 $groupList[$id]['group_name'] .= '<div class="crm-row-parent-name"><em>' . ts('Child of') . '</em>: ' . implode(', ', $title) . '</div>';
                 $value['class'] = array_diff($value['class'], array('crm-row-parent'));
             }
             $value['class'][] = 'crm-entity';
             $groupList[$id]['class'] = $value['id'] . ',' . implode(' ', $value['class']);
             $groupList[$id]['group_description'] = CRM_Utils_Array::value('description', $value);
             if (!empty($value['group_type'])) {
                 $groupList[$id]['group_type'] = $value['group_type'];
             } else {
                 $groupList[$id]['group_type'] = '';
             }
             $groupList[$id]['visibility'] = $value['visibility'];
             $groupList[$id]['links'] = $value['action'];
             $groupList[$id]['org_info'] = CRM_Utils_Array::value('org_info', $value);
             $groupList[$id]['created_by'] = CRM_Utils_Array::value('created_by', $value);
             $groupList[$id]['is_parent'] = $value['is_parent'];
         }
         return $groupList;
     }
 }
 /**
  * build form elements.
  * params object $form object of the form
  *
  * @param CRM_Core_Form $form
  *   The form object that we are operating on.
  * @param int $contactId
  *   Contact id.
  * @param int $type
  *   What components are we interested in.
  * @param bool $visibility
  *   Visibility of the field.
  * @param null $isRequired
  * @param string $groupName
  *   If used for building group block.
  * @param string $tagName
  *   If used for building tag block.
  * @param string $fieldName
  *   This is used in batch profile(i.e to build multiple blocks).
  *
  * @param string $groupElementType
  *
  */
 public static function buildQuickForm(&$form, $contactId = 0, $type = self::ALL, $visibility = FALSE, $isRequired = NULL, $groupName = 'Group(s)', $tagName = 'Tag(s)', $fieldName = NULL, $groupElementType = 'checkbox')
 {
     if (!isset($form->_tagGroup)) {
         $form->_tagGroup = array();
     }
     // NYSS 5670
     if (!$contactId && !empty($form->_contactId)) {
         $contactId = $form->_contactId;
     }
     $type = (int) $type;
     if ($type & self::GROUP) {
         $fName = 'group';
         if ($fieldName) {
             $fName = $fieldName;
         }
         $groupID = isset($form->_grid) ? $form->_grid : NULL;
         if ($groupID && $visibility) {
             $ids = array($groupID => $groupID);
         } else {
             if ($visibility) {
                 $group = CRM_Core_PseudoConstant::allGroup();
             } else {
                 $group = CRM_Core_PseudoConstant::group();
             }
             $ids = $group;
         }
         if ($groupID || !empty($group)) {
             $groups = CRM_Contact_BAO_Group::getGroupsHierarchy($ids);
             $attributes['skiplabel'] = TRUE;
             $elements = array();
             $groupsOptions = array();
             foreach ($groups as $id => $group) {
                 // make sure that this group has public visibility
                 if ($visibility && $group['visibility'] == 'User and User Admin Only') {
                     continue;
                 }
                 if ($groupElementType == 'select') {
                     $groupsOptions[$id] = $group['title'];
                 } else {
                     $form->_tagGroup[$fName][$id]['description'] = $group['description'];
                     $elements[] =& $form->addElement('advcheckbox', $id, NULL, $group['title'], $attributes);
                 }
             }
             if ($groupElementType == 'select' && !empty($groupsOptions)) {
                 $form->add('select', $fName, $groupName, $groupsOptions, FALSE, array('id' => $fName, 'multiple' => 'multiple', 'class' => 'crm-select2'));
                 $form->assign('groupCount', count($groupsOptions));
             }
             if ($groupElementType == 'checkbox' && !empty($elements)) {
                 $form->addGroup($elements, $fName, $groupName, '&nbsp;<br />');
                 $form->assign('groupCount', count($elements));
                 if ($isRequired) {
                     $form->addRule($fName, ts('%1 is a required field.', array(1 => $groupName)), 'required');
                 }
             }
             $form->assign('groupElementType', $groupElementType);
         }
     }
     if ($type & self::TAG) {
         $fName = 'tag';
         if ($fieldName) {
             $fName = $fieldName;
         }
         $form->_tagGroup[$fName] = 1;
         // get the list of all the categories
         $tags = new CRM_Core_BAO_Tag();
         $tree = $tags->getTree('civicrm_contact', TRUE);
         // let's not load jstree if there are not children. This also fixes blank
         // display at the beginning of checkboxes
         $loadJsTree = CRM_Utils_Array::retrieveValueRecursive($tree, 'children');
         $form->assign('loadjsTree', FALSE);
         if (!empty($loadJsTree)) {
             // CODE FROM CRM/Tag/Form/Tag.php //
             CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header');
             $form->assign('loadjsTree', TRUE);
         }
         $elements = array();
         self::climbtree($form, $tree, $elements);
         $form->addGroup($elements, $fName, $tagName, '<br />');
         $form->assign('tagCount', count($elements));
         $form->assign('tree', $tree);
         $form->assign('tag', $tree);
         $form->assign('entityID', $contactId);
         $form->assign('entityTable', 'civicrm_contact');
         if ($isRequired) {
             $form->addRule($fName, ts('%1 is a required field.', array(1 => $tagName)), 'required');
         }
         // build tag widget
         $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
         CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', $contactId, FALSE, TRUE);
     }
     $form->assign('tagGroup', $form->_tagGroup);
 }
예제 #9
0
 public static function &group($groupType = null, $excludeHidden = true)
 {
     return CRM_Core_PseudoConstant::allGroup($groupType, $excludeHidden);
 }
예제 #10
0
 /**
  * Get all groups from database, filtered by permissions
  * for this user
  *
  * @access public
  * @static
  *
  * @return array - array reference of all groups.
  *
  */
 function &group()
 {
     return CRM_Core_PseudoConstant::allGroup();
 }
 /**
  * This function is to build form elements
  * params object $form object of the form
  *
  * @param Object  $form        the form object that we are operating on
  * @param int     $contactId   contact id
  * @param int     $type        what components are we interested in
  * @param boolean $visibility  visibility of the field
  * @param string  $groupName   if used for building group block
  * @param string  $tagName     if used for building tag block
  * @param string  $fieldName   this is used in batch profile(i.e to build multiple blocks)
  *
  * @static
  * @access public
  */
 static function buildQuickForm(&$form, $contactId = 0, $type = self::ALL, $visibility = FALSE, $isRequired = NULL, $groupName = 'Group(s)', $tagName = 'Tag(s)', $fieldName = NULL, $groupElementType = 'checkbox')
 {
     if (!isset($form->_tagGroup)) {
         $form->_tagGroup = array();
     }
     // NYSS 5670
     if (!$contactId && !empty($form->_contactId)) {
         $contactId = $form->_contactId;
     }
     $type = (int) $type;
     if ($type & self::GROUP) {
         $fName = 'group';
         if ($fieldName) {
             $fName = $fieldName;
         }
         $groupID = isset($form->_grid) ? $form->_grid : NULL;
         if ($groupID && $visibility) {
             $ids = array($groupID => $groupID);
         } else {
             if ($visibility) {
                 $group = CRM_Core_PseudoConstant::allGroup();
             } else {
                 $group = CRM_Core_PseudoConstant::nestedGroup();
             }
             $ids = $group;
         }
         if ($groupID || !empty($group)) {
             $groups = CRM_Contact_BAO_Group::getGroupsHierarchy($ids);
             $attributes['skiplabel'] = TRUE;
             $elements = array();
             $groupsOptions = array();
             foreach ($groups as $id => $group) {
                 // make sure that this group has public visibility
                 if ($visibility && $group['visibility'] == 'User and User Admin Only') {
                     continue;
                 }
                 if ($groupElementType == 'crmasmSelect') {
                     $groupsOptions[$id] = $group['title'];
                 } else {
                     $form->_tagGroup[$fName][$id]['description'] = $group['description'];
                     $elements[] =& $form->addElement('advcheckbox', $id, NULL, $group['title'], $attributes);
                 }
             }
             if ($groupElementType == 'crmasmSelect' && !empty($groupsOptions)) {
                 $form->add('select', $fName, ts('%1', array(1 => $groupName)), $groupsOptions, FALSE, array('id' => $fName, 'multiple' => 'multiple', 'title' => ts('- select -')));
                 $form->assign('groupCount', count($groupsOptions));
             }
             if ($groupElementType == 'checkbox' && !empty($elements)) {
                 $form->addGroup($elements, $fName, $groupName, '&nbsp;<br />');
                 $form->assign('groupCount', count($elements));
                 if ($isRequired) {
                     $form->addRule($fName, ts('%1 is a required field.', array(1 => $groupName)), 'required');
                 }
             }
             $form->assign('groupElementType', $groupElementType);
         }
     }
     if ($type & self::TAG) {
         $fName = 'tag';
         if ($fieldName) {
             $fName = $fieldName;
         }
         $form->_tagGroup[$fName] = 1;
         $elements = array();
         $tag = CRM_Core_BAO_Tag::getTags();
         foreach ($tag as $id => $name) {
             $elements[] = $form->createElement('checkbox', $id, NULL, $name);
         }
         if (!empty($elements)) {
             $form->addGroup($elements, $fName, $tagName, '<br />');
             $form->assign('tagCount', count($elements));
         }
         if ($isRequired) {
             $form->addRule($fName, ts('%1 is a required field.', array(1 => $tagName)), 'required');
         }
         // build tag widget
         $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
         CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', $contactId, TRUE, TRUE);
     }
     $form->assign('tagGroup', $form->_tagGroup);
 }
예제 #12
0
파일: Team.php 프로젝트: agloa/tournament
 /**
  * Make sure that the user has permission to access this team.
  *
  * @param int $id
  *   The id of the object.
  * @param bool $excludeHidden
  *   Should hidden teams be excluded.
  *   Logically this is the wrong place to filter hidden groups out as that is
  *   not a permission issue. However, as other functions may rely on that defaulting to
  *   FALSE for now & only the api call is calling with true.
  *
  * @return array
  *   The permission that the user has (or NULL)
  */
 public static function checkPermission($id, $excludeHidden = FALSE)
 {
     $allGroups = CRM_Core_PseudoConstant::allGroup(NULL, $excludeHidden);
     // 		$permissions = NULL;
     // 		if (CRM_Core_Permission::check('edit all contacts') ||
     // 				CRM_ACL_API::groupPermission(CRM_ACL_API::EDIT, $id, NULL,
     // 						'civicrm_saved_search', $allGroups
     // 				)
     // 		) {
     // 			$permissions[] = CRM_Core_Permission::EDIT;
     // 		}
     $permissions[] = CRM_Core_Permission::EDIT;
     // 		if (CRM_Core_Permission::check('view all contacts') ||
     // 				CRM_ACL_API::groupPermission(CRM_ACL_API::VIEW, $id, NULL,
     // 						'civicrm_saved_search', $allGroups
     // 				)
     // 		) {
     // 			$permissions[] = CRM_Core_Permission::VIEW;
     // 		}
     $permissions[] = CRM_Core_Permission::VIEW;
     //if (!empty($permissions) && CRM_Core_Permission::check('delete contacts')) {
     if (!empty($permissions) && CRM_Core_Permission::check('edit groups')) {
         // Note: using !empty() in if condition, restricts the scope of delete
         // permission to groups/contacts that are editable/viewable.
         // We can remove this !empty condition once we have ACL support for delete functionality.
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     return $permissions;
 }
예제 #13
0
 /**
  * make sure that the user has permission to access this group
  *
  * @param int $id   the id of the object
  * @param int $name the name or title of the object
  *
  * @return string   the permission that the user has (or null)
  * @access public
  * @static
  */
 static function checkPermission($id, $title)
 {
     $allGroups = CRM_Core_PseudoConstant::allGroup();
     $permissions = NULL;
     if (CRM_Core_Permission::check('edit all contacts') || CRM_ACL_API::groupPermission(CRM_ACL_API::EDIT, $id, NULL, 'civicrm_saved_search', $allGroups)) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('view all contacts') || CRM_ACL_API::groupPermission(CRM_ACL_API::VIEW, $id, NULL, 'civicrm_saved_search', $allGroups)) {
         $permissions[] = CRM_Core_Permission::VIEW;
     }
     if (!empty($permissions) && CRM_Core_Permission::check('delete contacts')) {
         // Note: using !empty() in if condition, restricts the scope of delete
         // permission to groups/contacts that are editable/viewable.
         // We can remove this !empty condition once we have ACL support for delete functionality.
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     return $permissions;
 }
예제 #14
0
파일: Base.php 프로젝트: kidaa30/yes
 /**
  * Get all groups from database, filtered by permissions
  * for this user
  *
  * @param string $groupType
  *   Type of group(Access/Mailing).
  * @param bool $excludeHidden
  *   exclude hidden groups.
  *
  *
  * @return array
  *   array reference of all groups.
  */
 public function group($groupType = NULL, $excludeHidden = TRUE)
 {
     return CRM_Core_PseudoConstant::allGroup($groupType, $excludeHidden);
 }
예제 #15
0
 /**
  * This function is to build form elements
  * params object $form object of the form
  *
  * @param Object  $form        the form object that we are operating on
  * @param int     $contactId   contact id
  * @param int     $type        what components are we interested in 
  * @param boolean $visibility  visibility of the field
  * @param string  $groupName   if used for building group block
  * @param string  $tagName     if used for building tag block
  * @param string  $fieldName   this is used in batch profile(i.e to build multiple blocks)
  * 
  * @static
  * @access public
  */
 static function buildQuickForm(&$form, $contactId = 0, $type = CRM_Contact_Form_Edit_TagsandGroups::ALL, $visibility = false, $isRequired = null, $groupName = 'Groups(s)', $tagName = 'Tag(s)', $fieldName = null)
 {
     $type = (int) $type;
     if ($type & CRM_Contact_Form_Edit_TagsandGroups::GROUP) {
         $fName = 'group';
         if ($fieldName) {
             $fName = $fieldName;
         }
         $elements = array();
         $groupID = isset($form->_grid) ? $form->_grid : null;
         if ($groupID && $visibility) {
             $ids = '= ' . $groupID;
         } else {
             if ($visibility) {
                 $group =& CRM_Core_PseudoConstant::allGroup();
             } else {
                 $group =& CRM_Core_PseudoConstant::group();
             }
             $ids = implode(',', array_keys($group));
             $ids = 'IN (' . $ids . ')';
         }
         if ($groupID || !empty($group)) {
             $sql = "\n    SELECT   id, title, description, visibility\n    FROM     civicrm_group\n    WHERE    id {$ids}\n    ORDER BY title\n    ";
             $dao = CRM_Core_DAO::executeQuery($sql);
             $attributes['skiplabel'] = true;
             while ($dao->fetch()) {
                 // make sure that this group has public visibility
                 if ($visibility && $dao->visibility == 'User and User Admin Only') {
                     continue;
                 }
                 $form->_tagGroup[$fName][$dao->id]['description'] = $dao->description;
                 $elements[] =& $form->addElement('advcheckbox', $dao->id, null, $dao->title, $attributes);
             }
             if (!empty($elements)) {
                 $form->addGroup($elements, $fName, $groupName, '&nbsp;');
                 $form->assign('groupCount', count($elements));
                 if ($isRequired) {
                     $form->addRule($fName, ts('%1 is a required field.', array(1 => $groupName)), 'required');
                 }
             }
         }
     }
     if ($type & CRM_Contact_Form_Edit_TagsandGroups::TAG) {
         $fName = 'tag';
         if ($fieldName) {
             $fName = $fieldName;
         }
         $form->_tagGroup[$fName] = 1;
         $elements = array();
         $tag =& CRM_Core_PseudoConstant::tag();
         foreach ($tag as $id => $name) {
             $elements[] =& HTML_QuickForm::createElement('checkbox', $id, null, $name);
         }
         if (!empty($elements)) {
             $form->addGroup($elements, $fName, $tagName, '<br />');
             $form->assign('tagCount', count($elements));
         }
         if ($isRequired) {
             $form->addRule($fName, ts('%1 is a required field.', array(1 => $tagName)), 'required');
         }
     }
     $form->assign('tagGroup', $form->_tagGroup);
 }
예제 #16
0
 /**
  * Get all groups from database, filtered by permissions
  * for this user
  *
  * @access public
  * @static
  *
  * @return array - array reference of all groups.
  *
  */
 public static function &group($groupType = null)
 {
     return CRM_Core_PseudoConstant::allGroup($groupType);
 }
 /**
  * This function is to build form elements
  * params object $form object of the form
  *
  * @param Object  $form        the form object that we are operating on
  * @param int     $contactId   contact id
  * @param int     $type        what components are we interested in
  * @param boolean $visibility  visibility of the field
  * @param string  $groupName   if used for building group block
  * @param string  $tagName     if used for building tag block
  * @param string  $fieldName   this is used in batch profile(i.e to build multiple blocks)
  *
  * @static
  * @access public
  */
 static function buildQuickForm(&$form, $contactId = 0, $type = CRM_Contact_Form_Edit_TagsandGroups::ALL, $visibility = FALSE, $isRequired = NULL, $groupName = 'Group(s)', $tagName = 'Tag(s)', $fieldName = NULL)
 {
     if (!isset($form->_tagGroup)) {
         $form->_tagGroup = array();
     }
     // NYSS 5670
     if (!$contactId && !empty($form->_contactId)) {
         $contactId = $form->_contactId;
     }
     $type = (int) $type;
     if ($type & CRM_Contact_Form_Edit_TagsandGroups::GROUP) {
         $fName = 'group';
         if ($fieldName) {
             $fName = $fieldName;
         }
         $elements = array();
         $groupID = isset($form->_grid) ? $form->_grid : NULL;
         if ($groupID && $visibility) {
             $ids = "= {$groupID}";
         } else {
             if ($visibility) {
                 $group = CRM_Core_PseudoConstant::allGroup();
             } else {
                 $group = CRM_Core_PseudoConstant::group();
             }
             $ids = implode(',', array_keys($group));
             $ids = 'IN (' . $ids . ')';
         }
         if ($groupID || !empty($group)) {
             $sql = "\n    SELECT   id, title, description, visibility\n    FROM     civicrm_group\n    WHERE    id {$ids}\n    ORDER BY title\n    ";
             $dao = CRM_Core_DAO::executeQuery($sql);
             $attributes['skiplabel'] = TRUE;
             while ($dao->fetch()) {
                 // make sure that this group has public visibility
                 if ($visibility && $dao->visibility == 'User and User Admin Only') {
                     continue;
                 }
                 $form->_tagGroup[$fName][$dao->id]['description'] = $dao->description;
                 $elements[] =& $form->addElement('advcheckbox', $dao->id, NULL, $dao->title, $attributes);
             }
             if (!empty($elements)) {
                 $form->addGroup($elements, $fName, $groupName, '&nbsp;<br />');
                 $form->assign('groupCount', count($elements));
                 if ($isRequired) {
                     $form->addRule($fName, ts('%1 is a required field.', array(1 => $groupName)), 'required');
                 }
             }
         }
     }
     if ($type & CRM_Contact_Form_Edit_TagsandGroups::TAG) {
         $fName = 'tag';
         if ($fieldName) {
             $fName = $fieldName;
         }
         $form->_tagGroup[$fName] = 1;
         $elements = array();
         $tag = CRM_Core_BAO_Tag::getTags();
         foreach ($tag as $id => $name) {
             $elements[] = $form->createElement('checkbox', $id, NULL, $name);
         }
         if (!empty($elements)) {
             $form->addGroup($elements, $fName, $tagName, '<br />');
             $form->assign('tagCount', count($elements));
         }
         if ($isRequired) {
             $form->addRule($fName, ts('%1 is a required field.', array(1 => $tagName)), 'required');
         }
         // build tag widget
         $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
         CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', $contactId, FALSE, TRUE);
     }
     $form->assign('tagGroup', $form->_tagGroup);
 }