protected function getInput()
 {
     $value = $this->value;
     $name = $this->name;
     // Initiate CiviCRM
     define('CIVICRM_SETTINGS_PATH', JPATH_ROOT . '/' . 'administrator/components/com_civicrm/civicrm.settings.php');
     require_once CIVICRM_SETTINGS_PATH;
     require_once 'CRM/Core/ClassLoader.php';
     CRM_Core_ClassLoader::singleton()->register();
     require_once 'CRM/Core/Config.php';
     $config = CRM_Core_Config::singleton();
     $ufGroups = CRM_Core_PseudoConstant::ufGroup();
     $options[] = JHTML::_('select.option', '', JText::_('- Select Profile -'));
     foreach ($ufGroups as $key => $values) {
         $options[] = JHTML::_('select.option', $key, $values);
     }
     return JHTML::_('select.genericlist', $options, $name, NULL, 'value', 'text', $value);
 }
 public static function ufGroup($type = CRM_Core_Permission::VIEW)
 {
     $ufGroups = CRM_Core_PseudoConstant::ufGroup();
     $allGroups = array_keys($ufGroups);
     // check if user has all powerful permission
     if (self::check('profile listings and forms')) {
         return $allGroups;
     }
     switch ($type) {
         case CRM_Core_Permission::VIEW:
             if (self::check('profile view') || self::check('profile edit')) {
                 return $allGroups;
             }
             break;
         case CRM_Core_Permission::CREATE:
             if (self::check('profile create')) {
                 return $allGroups;
             }
             break;
         case CRM_Core_Permission::EDIT:
             if (self::check('profile edit')) {
                 return $allGroups;
             }
             break;
         case CRM_Core_Permission::SEARCH:
             if (self::check('profile listings')) {
                 return $allGroups;
             }
             break;
     }
     return CRM_ACL_API::group($type, NULL, 'civicrm_uf_group', $ufGroups);
 }
Example #3
0
 /** 
  * get all the listing fields 
  * 
  * @param int  $action            what action are we doing 
  * @param int  $visibility        visibility of fields we are interested in
  * @param bool $considerSelector  whether to consider the in_selector parameter
  * @param      $ufGroupId
  * @param      $searchable
  * 
  * @return array     the fields that are listings related
  * @static 
  * @access public 
  */
 static function getListingFields($action, $visibility, $considerSelector = false, $ufGroupId = null, $searchable = null, $restrict = null, $skipPermission = false, $permissionType = CRM_Core_Permission::SEARCH)
 {
     if ($ufGroupId) {
         $subset = self::getFields($ufGroupId, false, $action, $visibility, $searchable, false, $restrict, $skipPermission, null, $permissionType);
         if ($considerSelector) {
             // drop the fields not meant for the selector
             foreach ($subset as $name => $field) {
                 if (!$field['in_selector']) {
                     unset($subset[$name]);
                 }
             }
         }
         $fields = $subset;
     } else {
         $ufGroups =& CRM_Core_PseudoConstant::ufGroup();
         $fields = array();
         foreach ($ufGroups as $id => $title) {
             $subset = self::getFields($id, false, $action, $visibility, $searchable, false, $restrict, $skipPermission, null, $permissionType);
             if ($considerSelector) {
                 // drop the fields not meant for the selector
                 foreach ($subset as $name => $field) {
                     if (!$field['in_selector']) {
                         unset($subset[$name]);
                     }
                 }
             }
             $fields = array_merge($fields, $subset);
         }
     }
     return $fields;
 }
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $attributes = CRM_Core_DAO::getAttribute('CRM_ACL_DAO_ACL');
     $this->add('text', 'name', ts('Description'), CRM_Core_DAO::getAttribute('CRM_ACL_DAO_ACL', 'name'), TRUE);
     $operations = array('' => ts('- select -')) + CRM_ACL_BAO_ACL::operation();
     $this->add('select', 'operation', ts('Operation'), $operations, TRUE);
     $objTypes = array('1' => ts('A group of contacts'), '2' => ts('A profile'), '3' => ts('A set of custom data fields'));
     if (CRM_Core_Permission::access('CiviEvent')) {
         $objTypes['4'] = ts('Events');
     }
     $extra = array('onclick' => "showObjectSelect();");
     $this->addRadio('object_type', ts('Type of Data'), $objTypes, $extra, ' ', TRUE);
     $label = ts('Role');
     $role = array('-1' => ts('- select role -'), '0' => ts('Everyone')) + CRM_Core_OptionGroup::values('acl_role');
     $this->add('select', 'entity_id', $label, $role, TRUE);
     $group = array('-1' => ts('- select -'), '0' => ts('All Groups')) + CRM_Core_PseudoConstant::group();
     $customGroup = array('-1' => ts('- select -'), '0' => ts('All Custom Groups')) + CRM_Core_PseudoConstant::customGroup();
     $ufGroup = array('-1' => ts('- select -'), '0' => ts('All Profiles')) + CRM_Core_PseudoConstant::ufGroup();
     $event = array('-1' => ts('- select -'), '0' => ts('All Events')) + CRM_Event_PseudoConstant::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
     $this->add('select', 'group_id', ts('Group'), $group);
     $this->add('select', 'custom_group_id', ts('Custom Data'), $customGroup);
     $this->add('select', 'uf_group_id', ts('Profile'), $ufGroup);
     $this->add('select', 'event_id', ts('Event'), $event);
     $this->add('checkbox', 'is_active', ts('Enabled?'));
     $this->addFormRule(array('CRM_ACL_Form_ACL', 'formRule'));
 }
Example #5
0
 /**
  * get the title of the group which contributes the largest number of fields
  * to the registered entries
  *
  * @params null
  * 
  * @return string    title of the registered group.
  * @static
  * @access public
  */
 function getRegisteredTitle()
 {
     $ufGroups =& CRM_Core_PseudoConstant::ufGroup();
     $size = -1;
     $title = null;
     foreach ($ufGroups as $id => $value) {
         $subset = CRM_Core_BAO_UFGroup::getFields($id, true, $action);
         if (count($subset) > $size) {
             $size = count($subset);
             $title = $value;
         }
     }
     return $title;
 }
Example #6
0
/**                
 * Get all the user framework groups 
 * 
 * @access public                                         
 * @return array - array reference of all groups. 
 * @static 
 */
function &crm_uf_get_profile_groups()
{
    return CRM_Core_PseudoConstant::ufGroup();
}
Example #7
0
 /**
  * Browse all acls
  * 
  * @return void
  * @access public
  * @static
  */
 function browse()
 {
     require_once 'CRM/ACL/DAO/ACL.php';
     // get all acl's sorted by weight
     $acl = array();
     $query = "\n  SELECT *\n    FROM civicrm_acl\n   WHERE ( object_table IN ( 'civicrm_saved_search', 'civicrm_uf_group', 'civicrm_custom_group', 'civicrm_event' ) )\nORDER BY entity_id\n";
     $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
     require_once 'CRM/Core/OptionGroup.php';
     $roles = CRM_Core_OptionGroup::values('acl_role');
     $group = array('-1' => ts('- select -'), '0' => ts('All Groups')) + CRM_Core_PseudoConstant::group();
     $customGroup = array('-1' => ts('- select -'), '0' => ts('All Custom Groups')) + CRM_Core_PseudoConstant::customGroup();
     $ufGroup = array('-1' => ts('- select -'), '0' => ts('All Profiles')) + CRM_Core_PseudoConstant::ufGroup();
     require_once 'CRM/Event/PseudoConstant.php';
     $event = array('-1' => ts('- select -'), '0' => ts('All Events')) + CRM_Event_PseudoConstant::event();
     while ($dao->fetch()) {
         $acl[$dao->id] = array();
         $acl[$dao->id]['name'] = $dao->name;
         $acl[$dao->id]['operation'] = $dao->operation;
         $acl[$dao->id]['entity_id'] = $dao->entity_id;
         $acl[$dao->id]['entity_table'] = $dao->entity_table;
         $acl[$dao->id]['object_table'] = $dao->object_table;
         $acl[$dao->id]['object_id'] = $dao->object_id;
         $acl[$dao->id]['is_active'] = $dao->is_active;
         if ($acl[$dao->id]['entity_id']) {
             $acl[$dao->id]['entity'] = $roles[$acl[$dao->id]['entity_id']];
         } else {
             $acl[$dao->id]['entity'] = ts('Everyone');
         }
         switch ($acl[$dao->id]['object_table']) {
             case 'civicrm_saved_search':
                 $acl[$dao->id]['object'] = $group[$acl[$dao->id]['object_id']];
                 $acl[$dao->id]['object_name'] = ts('Group');
                 break;
             case 'civicrm_uf_group':
                 $acl[$dao->id]['object'] = $ufGroup[$acl[$dao->id]['object_id']];
                 $acl[$dao->id]['object_name'] = ts('Profile');
                 break;
             case 'civicrm_custom_group':
                 $acl[$dao->id]['object'] = $customGroup[$acl[$dao->id]['object_id']];
                 $acl[$dao->id]['object_name'] = ts('Custom Group');
                 break;
             case 'civicrm_event':
                 $acl[$dao->id]['object'] = $event[$acl[$dao->id]['object_id']];
                 $acl[$dao->id]['object_name'] = ts('Event');
                 break;
         }
         // form all action links
         $action = array_sum(array_keys($this->links()));
         if ($dao->is_active) {
             $action -= CRM_Core_Action::ENABLE;
         } else {
             $action -= CRM_Core_Action::DISABLE;
         }
         $acl[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id));
     }
     $this->assign('rows', $acl);
 }
Example #8
0
 /**
  * Browse all uf data groups.
  *
  * @param
  * @return void
  * @access public
  * @static
  */
 function browse($action = null)
 {
     $ufGroup = array();
     $allUFGroups = array();
     require_once 'CRM/Core/BAO/UFGroup.php';
     $allUFGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup();
     if (empty($allUFGroups)) {
         return;
     }
     require_once 'CRM/Utils/Hook.php';
     $ufGroups = CRM_Core_PseudoConstant::ufGroup();
     CRM_Utils_Hook::aclGroup(CRM_Core_Permission::ADMIN, null, 'civicrm_uf_group', $ufGroups, $allUFGroups);
     foreach ($allUFGroups as $id => $value) {
         $ufGroup[$id] = array();
         $ufGroup[$id]['id'] = $id;
         $ufGroup[$id]['title'] = $value['title'];
         $ufGroup[$id]['is_active'] = $value['is_active'];
         $ufGroup[$id]['group_type'] = $value['group_type'];
         $ufGroup[$id]['is_reserved'] = $value['is_reserved'];
         // form all action links
         $action = array_sum(array_keys($this->actionLinks()));
         // update enable/disable links depending on uf_group properties.
         if ($value['is_active']) {
             $action -= CRM_Core_Action::ENABLE;
         } else {
             $action -= CRM_Core_Action::DISABLE;
         }
         // drop certain actions if the profile is reserved
         if ($value['is_reserved']) {
             $action -= CRM_Core_Action::UPDATE;
             $action -= CRM_Core_Action::DISABLE;
             $action -= CRM_Core_Action::DELETE;
         }
         // drop Create, Edit and View mode links if profile group_type is Contribution, Membership, or Participant
         if ($value['group_type'] == 'Contribution' || $value['group_type'] == 'Membership' || $value['group_type'] == 'Participant') {
             $action -= CRM_Core_Action::ADD;
         }
         $ufGroup[$id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $id));
         //get the "Used For" from uf_join
         $ufGroup[$id]['module'] = implode(', ', CRM_Core_BAO_UFGroup::getUFJoinRecord($id, true));
     }
     $this->assign('rows', $ufGroup);
 }
Example #9
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 function buildQuickForm()
 {
     $this->add('select', 'custom_pre_id', ts('Custom Fields') . '<br />' . ts('(above billing info)'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::ufGroup());
     $this->add('select', 'custom_post_id', ts('Custom Fields') . '<br />' . ts('(below billing info)'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::ufGroup());
     parent::buildQuickForm();
 }
Example #10
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     //lets have single status message, CRM-4363
     $return = false;
     $statusMessage = null;
     //we should not allow component and mix profiles in search mode
     if ($this->_mode != self::MODE_REGISTER) {
         //check for mix profile fields (eg:  individual + other contact type)
         if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) {
             $statusMessage = ts('Profile search, view and edit are not supported for Profiles which include fields for more than one record type.');
         }
         $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid);
         if ($this->_id) {
             list($contactType, $contactSubType) = CRM_Contact_BAO_Contact::getContactTypes($this->_id);
             $profileSubType = false;
             if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
                 $profileSubType = $profileType;
                 $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
             }
             if ($profileType != 'Contact' && ($profileSubType && $contactSubType && $profileSubType != $contactSubType || $profileType != $contactType)) {
                 $return = true;
                 if (!$statusMessage) {
                     $statusMessage = ts("This profile is configured for contact type '%1'. It cannot be used to edit contacts of other types.", array(1 => $profileSubType ? $profileSubType : $profileType));
                 }
             }
         }
         if (in_array($profileType, array("Membership", "Participant", "Contribution"))) {
             $return = true;
             if (!$statusMessage) {
                 $statusMessage = ts('Profile is not configured for the selected action.');
             }
         }
     }
     //lets have sigle status message,
     $this->assign('statusMessage', $statusMessage);
     if ($return) {
         return false;
     }
     $sBlocks = array();
     $hBlocks = array();
     $config =& CRM_Core_Config::singleton();
     $this->assign('id', $this->_id);
     $this->assign('mode', $this->_mode);
     $this->assign('action', $this->_action);
     $this->assign_by_ref('fields', $this->_fields);
     $this->assign('fieldset', isset($this->_fieldset) ? $this->_fieldset : "");
     // do we need inactive options ?
     if ($this->_action & CRM_Core_Action::VIEW) {
         $inactiveNeeded = true;
     } else {
         $inactiveNeeded = false;
     }
     $session =& CRM_Core_Session::singleton();
     // should we restrict what we display
     $admin = true;
     if ($this->_mode == self::MODE_EDIT) {
         $admin = false;
         // show all fields that are visibile:
         // if we are a admin OR the same user OR acl-user with access to the profile
         require_once 'CRM/ACL/API.php';
         if (CRM_Core_Permission::check('administer users') || $this->_id == $session->get('userID') || in_array($this->_gid, CRM_ACL_API::group(CRM_Core_Permission::EDIT, null, 'civicrm_uf_group', CRM_Core_PseudoConstant::ufGroup()))) {
             $admin = true;
         }
     }
     $userID = $session->get('userID');
     $anonUser = false;
     // if false, user is not logged-in.
     if (!$userID) {
         require_once 'CRM/Core/BAO/LocationType.php';
         $defaultLocationType =& CRM_Core_BAO_LocationType::getDefault();
         $primaryLocationType = $defaultLocationType->id;
         $anonUser = true;
         $this->assign('anonUser', true);
     }
     $addCaptcha = array();
     $emailPresent = false;
     // cache the state country fields. based on the results, we could use our javascript solution
     // in create or register mode
     $stateCountryMap = array();
     // add the form elements
     foreach ($this->_fields as $name => $field) {
         // make sure that there is enough permission to expose this field
         if (!$admin && $field['visibility'] == 'User and User Admin Only' || CRM_Utils_Array::value('is_view', $field)) {
             unset($this->_fields[$name]);
             continue;
         }
         // since the CMS manages the email field, suppress the email display if in
         // register mode which occur within the CMS form
         if ($this->_mode == self::MODE_REGISTER && substr($name, 0, 5) == 'email') {
             unset($this->_fields[$name]);
             continue;
         }
         list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
         if ($prefixName == 'state_province' || $prefixName == 'country') {
             if (!array_key_exists($index, $stateCountryMap)) {
                 $stateCountryMap[$index] = array();
             }
             $stateCountryMap[$index][$prefixName] = $name;
         }
         CRM_Core_BAO_UFGroup::buildProfile($this, $field, $this->_mode);
         if ($field['add_to_group_id']) {
             $addToGroupId = $field['add_to_group_id'];
         }
         //build array for captcha
         if ($field['add_captcha']) {
             $addCaptcha[$field['group_id']] = $field['add_captcha'];
         }
         if ($name == 'email-Primary' || ($name == 'email-' . isset($primaryLocationType) ? $primaryLocationType : "")) {
             $emailPresent = true;
             $this->_mail = $name;
         }
     }
     // add captcha only for create mode.
     if ($this->_mode == self::MODE_CREATE) {
         if (!$this->_isAddCaptcha && !empty($addCaptcha)) {
             $this->_isAddCaptcha = true;
         }
     } else {
         $this->_isAddCaptcha = false;
     }
     //finally add captcha to form.
     if ($this->_isAddCaptcha) {
         require_once 'CRM/Utils/ReCAPTCHA.php';
         $captcha =& CRM_Utils_ReCAPTCHA::singleton();
         $captcha->add($this);
     }
     $this->assign("isCaptcha", $this->_isAddCaptcha);
     if ($this->_mode != self::MODE_SEARCH) {
         if (isset($addToGroupId)) {
             $this->add('hidden', "group[{$addToGroupId}]", 1);
             $this->_addToGroupID = $addToGroupId;
         }
     }
     // also do state country js
     require_once 'CRM/Core/BAO/Address.php';
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap, $this->_defaults);
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, false, null);
     if ($this->_mode == self::MODE_CREATE) {
         require_once 'CRM/Core/BAO/CMSUser.php';
         CRM_Core_BAO_CMSUser::buildForm($this, $this->_gid, $emailPresent, $action);
     } else {
         $this->assign('showCMS', false);
     }
     $this->assign('groupId', $this->_gid);
     // now fix all state country selectors
     require_once 'CRM/Core/BAO/Address.php';
     CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
     }
     if ($this->_context == 'dialog') {
         $this->addElement('submit', $this->_duplicateButtonName, ts('Save Matching Contact'));
     }
 }
 /**
  * Browse all uf data groups.
  *
  * @param
  *
  * @return void
  * @access public
  * @static
  */
 function browse($action = NULL)
 {
     $ufGroup = array();
     $allUFGroups = array();
     $allUFGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup();
     if (empty($allUFGroups)) {
         return;
     }
     $ufGroups = CRM_Core_PseudoConstant::ufGroup();
     CRM_Utils_Hook::aclGroup(CRM_Core_Permission::ADMIN, NULL, 'civicrm_uf_group', $ufGroups, $allUFGroups);
     foreach ($allUFGroups as $id => $value) {
         $ufGroup[$id] = array();
         $ufGroup[$id]['id'] = $id;
         $ufGroup[$id]['title'] = $value['title'];
         $ufGroup[$id]['is_active'] = $value['is_active'];
         $ufGroup[$id]['group_type'] = $value['group_type'];
         $ufGroup[$id]['is_reserved'] = $value['is_reserved'];
         // form all action links
         $action = array_sum(array_keys($this->actionLinks()));
         // update enable/disable links depending on uf_group properties.
         if ($value['is_active']) {
             $action -= CRM_Core_Action::ENABLE;
         } else {
             $action -= CRM_Core_Action::DISABLE;
         }
         // drop certain actions if the profile is reserved
         if ($value['is_reserved']) {
             $action -= CRM_Core_Action::UPDATE;
             $action -= CRM_Core_Action::DISABLE;
             $action -= CRM_Core_Action::DELETE;
         }
         $groupTypes = self::extractGroupTypes($value['group_type']);
         $groupComponents = array('Contribution', 'Membership', 'Activity', 'Participant');
         // drop Create, Edit and View mode links if profile group_type is Contribution, Membership, Activities or Participant
         $componentFound = array_intersect($groupComponents, array_keys($groupTypes));
         if (!empty($componentFound)) {
             $action -= CRM_Core_Action::ADD;
         }
         $groupTypesString = '';
         if (!empty($groupTypes)) {
             $groupTypesStrings = array();
             foreach ($groupTypes as $groupType => $typeValues) {
                 if (is_array($typeValues)) {
                     if ($groupType == 'Participant') {
                         foreach ($typeValues as $subType => $subTypeValues) {
                             $groupTypesStrings[] = $subType . '::' . implode(': ', $subTypeValues);
                         }
                     } else {
                         $groupTypesStrings[] = $groupType . '::' . implode(': ', current($typeValues));
                     }
                 } else {
                     $groupTypesStrings[] = $groupType;
                 }
             }
             $groupTypesString = implode(', ', $groupTypesStrings);
         }
         $ufGroup[$id]['group_type'] = $groupTypesString;
         $ufGroup[$id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $id));
         //get the "Used For" from uf_join
         $ufGroup[$id]['module'] = implode(', ', CRM_Core_BAO_UFGroup::getUFJoinRecord($id, TRUE));
     }
     $this->assign('rows', $ufGroup);
 }