示例#1
0
 /**
  * Register profile scripts.
  */
 public static function registerProfileScripts()
 {
     static $loaded = FALSE;
     if ($loaded || CRM_Core_Resources::isAjaxMode()) {
         return;
     }
     $loaded = TRUE;
     CRM_Core_Resources::singleton()->addSettingsFactory(function () {
         $ufGroups = civicrm_api3('UFGroup', 'get', array('sequential' => 1, 'is_active' => 1, 'options' => array('limit' => 0)));
         //CRM-16915 - insert 'module' param for the profile used by CiviEvent.
         if (CRM_Core_Permission::check('manage event profiles') && !CRM_Core_Permission::check('administer CiviCRM')) {
             foreach ($ufGroups['values'] as $key => $value) {
                 $ufJoin = CRM_Core_BAO_UFGroup::getUFJoinRecord($value['id']);
                 if (in_array('CiviEvent', $ufJoin) || in_array('CiviEvent_Additional', $ufJoin)) {
                     $ufGroups['values'][$key]['module'] = 'CiviEvent';
                 }
             }
         }
         return array('PseudoConstant' => array('locationType' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'), 'websiteType' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'), 'phoneType' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id')), 'initialProfileList' => $ufGroups, 'contactSubTypes' => CRM_Contact_BAO_ContactType::subTypes(), 'profilePreviewKey' => CRM_Core_Key::get('CRM_UF_Form_Inline_Preview', TRUE));
     })->addScriptFile('civicrm', 'packages/backbone/json2.js', 100, 'html-header', FALSE)->addScriptFile('civicrm', 'packages/backbone/backbone.js', 120, 'html-header')->addScriptFile('civicrm', 'packages/backbone/backbone.marionette.js', 125, 'html-header', FALSE)->addScriptFile('civicrm', 'packages/backbone/backbone.collectionsubset.js', 125, 'html-header', FALSE)->addScriptFile('civicrm', 'packages/backbone-forms/distribution/backbone-forms.js', 130, 'html-header', FALSE)->addScriptFile('civicrm', 'packages/backbone-forms/distribution/adapters/backbone.bootstrap-modal.min.js', 140, 'html-header', FALSE)->addScriptFile('civicrm', 'packages/backbone-forms/distribution/editors/list.min.js', 140, 'html-header', FALSE)->addStyleFile('civicrm', 'packages/backbone-forms/distribution/templates/default.css', 140, 'html-header')->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')->addStyleFile('civicrm', 'css/crm.designer.css', 140, 'html-header')->addScriptFile('civicrm', 'js/crm.backbone.js', 150)->addScriptFile('civicrm', 'js/model/crm.schema-mapped.js', 200)->addScriptFile('civicrm', 'js/model/crm.uf.js', 200)->addScriptFile('civicrm', 'js/model/crm.designer.js', 200)->addScriptFile('civicrm', 'js/model/crm.profile-selector.js', 200)->addScriptFile('civicrm', 'js/view/crm.designer.js', 200)->addScriptFile('civicrm', 'js/view/crm.profile-selector.js', 200)->addScriptFile('civicrm', 'js/jquery/jquery.crmProfileSelector.js', 250)->addScriptFile('civicrm', 'js/crm.designerapp.js', 250);
     CRM_Core_Region::instance('page-header')->add(array('template' => 'CRM/UF/Page/ProfileTemplates.tpl'));
 }
示例#2
0
文件: Group.php 项目: hguru/224Civi
 /**
  * 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::get('CRM_Core_DAO_UFField', 'uf_group_id');
     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]['created_id'] = $value['created_id'];
         $ufGroup[$id]['created_by'] = CRM_Contact_BAO_Contact::displayName($value['created_id']);
         $ufGroup[$id]['description'] = $value['description'];
         $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);
 }
示例#3
0
 /**
  * Make uf join entries for an uf group.
  *
  * @param array $params
  *   (reference) an assoc array of name/value pairs.
  * @param int $ufGroupId
  *   Ufgroup id.
  */
 public static function createUFJoin(&$params, $ufGroupId)
 {
     $groupTypes = CRM_Utils_Array::value('uf_group_type', $params);
     // get ufjoin records for uf group
     $ufGroupRecord = CRM_Core_BAO_UFGroup::getUFJoinRecord($ufGroupId);
     // get the list of all ufgroup types
     $allUFGroupType = CRM_Core_SelectValues::ufGroupTypes();
     // this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input
     if (!is_array($groupTypes)) {
         $groupTypes = array();
     }
     // this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input
     if (!is_array($ufGroupRecord)) {
         $ufGroupRecord = array();
     }
     // check which values has to be inserted/deleted for contact
     $menuRebuild = FALSE;
     foreach ($allUFGroupType as $key => $value) {
         $joinParams = array();
         $joinParams['uf_group_id'] = $ufGroupId;
         $joinParams['module'] = $key;
         if ($key == 'User Account') {
             $menuRebuild = TRUE;
         }
         if (array_key_exists($key, $groupTypes) && !in_array($key, $ufGroupRecord)) {
             // insert a new record
             CRM_Core_BAO_UFGroup::addUFJoin($joinParams);
         } elseif (!array_key_exists($key, $groupTypes) && in_array($key, $ufGroupRecord)) {
             // delete a record for existing ufgroup
             CRM_Core_BAO_UFGroup::delUFJoin($joinParams);
         }
     }
     //update the weight
     $query = "\nUPDATE civicrm_uf_join\nSET    weight = %1\nWHERE  uf_group_id = %2\nAND    ( entity_id IS NULL OR entity_id <= 0 )\n";
     $p = array(1 => array($params['weight'], 'Integer'), 2 => array($ufGroupId, 'Integer'));
     CRM_Core_DAO::executeQuery($query, $p);
     // do a menu rebuild if we are on drupal, so it gets all the new menu entries
     // for user account
     $config = CRM_Core_Config::singleton();
     if ($menuRebuild && $config->userSystem->is_drupal) {
         menu_rebuild();
     }
 }
示例#4
0
 /**
  * Browse all uf data groups.
  *
  * @param
  *
  * @return void
  */
 public function browse($action = NULL)
 {
     $ufGroup = array();
     $allUFGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup();
     if (empty($allUFGroups)) {
         return;
     }
     $ufGroups = CRM_Core_PseudoConstant::get('CRM_Core_DAO_UFField', 'uf_group_id');
     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]['created_id'] = $value['created_id'];
         $ufGroup[$id]['created_by'] = CRM_Contact_BAO_Contact::displayName($value['created_id']);
         $ufGroup[$id]['description'] = $value['description'];
         $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(self::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']);
         // drop Create, Edit and View mode links if profile group_type is one of the following:
         // Contribution, Membership, Activity, Participant, Case, Grant
         $isMixedProfile = CRM_Core_BAO_UFField::checkProfileType($id);
         if ($isMixedProfile) {
             $action -= CRM_Core_Action::ADD;
             $action -= CRM_Core_Action::ADVANCED;
             $action -= CRM_Core_Action::BASIC;
             $action -= CRM_Core_Action::PROFILE;
         }
         $ufGroup[$id]['group_type'] = self::formatGroupTypes($groupTypes);
         $ufGroup[$id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $id), ts('more'), FALSE, 'ufGroup.row.actions', 'UFGroup', $id);
         //get the "Used For" from uf_join
         $ufGroup[$id]['module'] = implode(', ', CRM_Core_BAO_UFGroup::getUFJoinRecord($id, TRUE));
     }
     $this->assign('rows', $ufGroup);
 }
示例#5
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return void
  */
 function setDefaultValues()
 {
     $defaults = array();
     $showHide = new CRM_Core_ShowHideBlocks();
     if ($this->_action == CRM_Core_Action::ADD) {
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_UFJoin');
     }
     //id fetched for Dojo Pane
     $pId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     if (isset($pId)) {
         $this->_id = $pId;
     }
     if (isset($this->_id)) {
         $defaults['weight'] = CRM_Core_BAO_UFGroup::getWeight($this->_id);
         $params = array('id' => $this->_id);
         CRM_Core_BAO_UFGroup::retrieve($params, $defaults);
         $defaults['group'] = CRM_Utils_Array::value('limit_listings_group_id', $defaults);
         $defaults['add_contact_to_group'] = CRM_Utils_Array::value('add_to_group_id', $defaults);
         //get the uf join records for current uf group
         $ufJoinRecords = CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_id);
         foreach ($ufJoinRecords as $key => $value) {
             $checked[$value] = 1;
         }
         $defaults['uf_group_type'] = isset($checked) ? $checked : "";
         //get the uf join records for current uf group other than default modules
         $otherModules = array();
         $otherModules = CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_id, TRUE, TRUE);
         if (!empty($otherModules)) {
             $otherModuleString = NULL;
             foreach ($otherModules as $key) {
                 $otherModuleString .= " [ x ] <label>" . $key . "</label>";
             }
             $this->assign('otherModuleString', $otherModuleString);
         }
         $showAdvanced = 0;
         $advFields = array('group', 'post_URL', 'cancel_URL', 'add_captcha', 'is_map', 'is_uf_link', 'is_edit_link', 'is_update_dupe', 'is_cms_user', 'is_proximity_search');
         foreach ($advFields as $key) {
             if (!empty($defaults[$key])) {
                 $showAdvanced = 1;
                 $this->_allPanes['Advanced Settings']['open'] = 'true';
                 break;
             }
         }
     } else {
         $defaults['is_active'] = 1;
         $defaults['is_map'] = 0;
         $defaults['is_update_dupe'] = 0;
         $defaults['is_proximity_search'] = 0;
     }
     // Don't assign showHide elements to template in DELETE mode (fields to be shown and hidden don't exist)
     if (!($this->_action & CRM_Core_Action::DELETE) && !($this->_action & CRM_Core_Action::DISABLE)) {
         $showHide->addToTemplate();
     }
     $this->assign('allPanes', $this->_allPanes);
     return $defaults;
 }
示例#6
0
 /**
  * Function to make uf join entries for an uf group
  *
  * @param array $params       (reference) an assoc array of name/value pairs
  * @param int   $ufGroupId    ufgroup id
  *
  * @return void
  * @access public
  * @static
  */
 function createUFJoin(&$params, $ufGroupId)
 {
     $groupTypes = $params['uf_group_type'];
     // get ufjoin records for uf group
     $ufGroupRecord =& CRM_Core_BAO_UFGroup::getUFJoinRecord($ufGroupId);
     // get the list of all ufgroup types
     $allUFGroupType =& CRM_Core_SelectValues::ufGroupTypes();
     // this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input
     if (!is_array($groupTypes)) {
         $groupTypes = array();
     }
     // this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input
     if (!is_array($ufGroupRecord)) {
         $ufGroupRecord = array();
     }
     // check which values has to be inserted/deleted for contact
     foreach ($allUFGroupType as $key => $value) {
         $joinParams = array();
         $joinParams['uf_group_id'] = $ufGroupId;
         $joinParams['module'] = $key;
         if (array_key_exists($key, $groupTypes) && !in_array($key, $ufGroupRecord)) {
             // insert a new record
             CRM_Core_BAO_UFGroup::addUFJoin($joinParams);
         } else {
             if (!array_key_exists($key, $groupTypes) && in_array($key, $ufGroupRecord)) {
                 // delete a record for existing ufgroup
                 CRM_Core_BAO_UFGroup::delUFJoin($joinParams);
             }
         }
     }
     //update the weight for remaining group
     CRM_Core_BAO_UFGroup::updateWeight($params['weight'], $ufGroupId);
 }
示例#7
0
文件: Group.php 项目: ksecor/civicrm
 /**
  * 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;
     }
     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;
         }
         $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);
 }
示例#8
0
文件: Field.php 项目: kidaa30/yes
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Profile Field'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if (isset($this->_id)) {
         $params = array('id' => $this->_id);
         CRM_Core_BAO_UFField::retrieve($params, $defaults);
         // set it to null if so (avoids crappy E_NOTICE errors below
         $defaults['location_type_id'] = CRM_Utils_Array::value('location_type_id', $defaults);
         $specialFields = CRM_Core_BAO_UFGroup::getLocationFields();
         if (!$defaults['location_type_id'] && $defaults["field_type"] != "Formatting" && in_array($defaults['field_name'], $specialFields)) {
             $defaults['location_type_id'] = 0;
         }
         $defaults['field_name'] = array($defaults['field_type'], $defaults['field_type'] == "Formatting" ? "" : $defaults['field_name'], $defaults['field_name'] == "url" ? $defaults['website_type_id'] : $defaults['location_type_id'], CRM_Utils_Array::value('phone_type_id', $defaults));
         $this->_gid = $defaults['uf_group_id'];
     } else {
         $defaults['is_active'] = 1;
     }
     $otherModules = array_values(CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_gid));
     $this->assign('otherModules', $otherModules);
     if ($this->_action & CRM_Core_Action::ADD) {
         $fieldValues = array('uf_group_id' => $this->_gid);
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_UFField', $fieldValues);
     }
     // lets trim all the whitespace
     $this->applyFilter('__ALL__', 'trim');
     //hidden field to catch the group id in profile
     $this->add('hidden', 'group_id', $this->_gid);
     //hidden field to catch the field id in profile
     $this->add('hidden', 'field_id', $this->_id);
     $fields = CRM_Core_BAO_UFField::getAvailableFields($this->_gid, $defaults);
     $noSearchable = $hasWebsiteTypes = array();
     $addressCustomFields = array_keys(CRM_Core_BAO_CustomField::getFieldsForImport('Address'));
     foreach ($fields as $key => $value) {
         foreach ($value as $key1 => $value1) {
             //CRM-2676, replacing the conflict for same custom field name from different custom group.
             if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key1)) {
                 $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $customFieldId, 'custom_group_id');
                 $customGroupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'title');
                 $this->_mapperFields[$key][$key1] = $value1['title'] . ' :: ' . $customGroupName;
                 if (in_array($key1, $addressCustomFields)) {
                     $noSearchable[] = $value1['title'] . ' :: ' . $customGroupName;
                 }
             } else {
                 $this->_mapperFields[$key][$key1] = $value1['title'];
             }
             $hasLocationTypes[$key][$key1] = CRM_Utils_Array::value('hasLocationType', $value1);
             $hasWebsiteTypes[$key][$key1] = CRM_Utils_Array::value('hasWebsiteType', $value1);
             // hide the 'is searchable' field for 'File' custom data
             if (isset($value1['data_type']) && isset($value1['html_type']) && ($value1['data_type'] == 'File' && $value1['html_type'] == 'File' || $value1['data_type'] == 'Link' && $value1['html_type'] == 'Link')) {
                 if (!in_array($value1['title'], $noSearchable)) {
                     $noSearchable[] = $value1['title'];
                 }
             }
         }
     }
     $this->assign('noSearchable', $noSearchable);
     $this->_location_types = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
     $this->_website_types = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id');
     /**
      * FIXME: dirty hack to make the default option show up first.  This
      * avoids a mozilla browser bug with defaults on dynamically constructed
      * selector widgets.
      */
     if ($defaultLocationType) {
         $defaultLocation = $this->_location_types[$defaultLocationType->id];
         unset($this->_location_types[$defaultLocationType->id]);
         $this->_location_types = array($defaultLocationType->id => $defaultLocation) + $this->_location_types;
     }
     $this->_location_types = array('Primary') + $this->_location_types;
     // since we need a hierarchical list to display contact types & subtypes,
     // this is what we going to display in first selector
     $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, FALSE);
     unset($contactTypes['']);
     $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array();
     $sel1 = array('' => '- select -') + $contactTypes;
     if (!empty($fields['Activity'])) {
         $sel1['Activity'] = 'Activity';
     }
     if (CRM_Core_Permission::access('CiviEvent')) {
         $sel1['Participant'] = 'Participants';
     }
     if (!empty($fields['Contribution'])) {
         $sel1['Contribution'] = 'Contributions';
     }
     if (!empty($fields['Membership'])) {
         $sel1['Membership'] = 'Membership';
     }
     if (!empty($fields['Case'])) {
         $sel1['Case'] = 'Case';
     }
     if (!empty($fields['Formatting'])) {
         $sel1['Formatting'] = 'Formatting';
     }
     foreach ($sel1 as $key => $sel) {
         if ($key) {
             $sel2[$key] = $this->_mapperFields[$key];
         }
     }
     $sel3[''] = NULL;
     $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
     ksort($phoneTypes);
     foreach ($sel1 as $k => $sel) {
         if ($k) {
             foreach ($this->_location_types as $key => $value) {
                 $sel4[$k]['phone'][$key] =& $phoneTypes;
                 $sel4[$k]['phone_and_ext'][$key] =& $phoneTypes;
             }
         }
     }
     foreach ($sel1 as $k => $sel) {
         if ($k) {
             if (is_array($this->_mapperFields[$k])) {
                 foreach ($this->_mapperFields[$k] as $key => $value) {
                     if ($hasLocationTypes[$k][$key]) {
                         $sel3[$k][$key] = $this->_location_types;
                     } elseif ($hasWebsiteTypes[$k][$key]) {
                         $sel3[$k][$key] = $this->_website_types;
                     } else {
                         $sel3[$key] = NULL;
                     }
                 }
             }
         }
     }
     $this->_defaults = array();
     $js = "<script type='text/javascript'>\n";
     $formName = "document.{$this->_name}";
     $alreadyMixProfile = FALSE;
     if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) {
         $alreadyMixProfile = TRUE;
     }
     $this->assign('alreadyMixProfile', $alreadyMixProfile);
     $sel =& $this->addElement('hierselect', 'field_name', ts('Field Name'));
     $formValues = $this->exportValues();
     if (empty($formValues)) {
         for ($k = 1; $k < 4; $k++) {
             if (!isset($defaults['field_name'][$k])) {
                 $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n";
             }
         }
     } else {
         if (!empty($formValues['field_name'])) {
             for ($key = 1; $key < 4; $key++) {
                 if (!isset($formValues['field_name'][$key])) {
                     $js .= "{$formName}['field_name[{$key}]'].style.display = 'none';\n";
                 } else {
                     $js .= "{$formName}['field_name[{$key}]'].style.display = '';\n";
                 }
             }
         } else {
             for ($k = 1; $k < 4; $k++) {
                 if (!isset($defaults['field_name'][$k])) {
                     $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n";
                 }
             }
         }
     }
     foreach ($sel2 as $k => $v) {
         if (is_array($sel2[$k])) {
             asort($sel2[$k]);
         }
     }
     $sel->setOptions(array($sel1, $sel2, $sel3, $sel4));
     // proper interpretation of spec in CRM-8732
     if (!isset($this->_id) && in_array('Search Profile', $otherModules)) {
         $defaults['visibility'] = 'Public Pages and Listings';
     }
     $js .= "</script>\n";
     $this->assign('initHideBoxes', $js);
     $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::ufVisibility(), TRUE, array('onChange' => "showHideSeletorSearch(this.value);"));
     //CRM-4363
     $js = array('onChange' => "mixProfile();");
     // should the field appear in selectors (as a column)?
     $this->add('checkbox', 'in_selector', ts('Results Column?'), NULL, NULL, $js);
     $this->add('checkbox', 'is_searchable', ts('Searchable?'), NULL, NULL, $js);
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField');
     // weight
     $this->add('text', 'weight', ts('Order'), $attributes['weight'], TRUE);
     $this->addRule('weight', ts('is a numeric field'), 'numeric');
     $this->add('textarea', 'help_pre', ts('Field Pre Help'), $attributes['help_pre']);
     $this->add('textarea', 'help_post', ts('Field Post Help'), $attributes['help_post']);
     $this->add('checkbox', 'is_required', ts('Required?'));
     $this->add('checkbox', 'is_multi_summary', ts('Include in multi-record listing?'));
     $this->add('checkbox', 'is_active', ts('Active?'));
     $this->add('checkbox', 'is_view', ts('View Only?'));
     // $this->add( 'checkbox', 'is_registration', ts( 'Display in Registration Form?' ) );
     //$this->add( 'checkbox', 'is_match'       , ts( 'Key to Match Contacts?'        ) );
     $this->add('text', 'label', ts('Field Label'), $attributes['label']);
     $js = NULL;
     if ($this->_hasSearchableORInSelector) {
         $js = array('onclick' => "return verify( );");
     }
     // add buttons
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE, 'js' => $js), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $js), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->addFormRule(array('CRM_UF_Form_Field', 'formRule'), $this);
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
         $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/uf/group/field?reset=1&action=browse&gid=" . $this->_gid . "'"));
     }
     $this->setDefaults($defaults);
 }
示例#9
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  * @return void
  */
 function setDefaultValues()
 {
     $defaults = array();
     if ($this->_action == CRM_CORE_ACTION_ADD) {
         $defaults['weight'] = CRM_Core_BAO_UFGroup::getWeight();
         $UFGroupType = CRM_Core_SelectValues::ufGroupTypes();
         foreach ($UFGroupType as $key => $value) {
             $checked[$key] = 1;
         }
         $defaults['uf_group_type'] = $checked;
     }
     if (isset($this->_id)) {
         $defaults['weight'] = CRM_Core_BAO_UFGroup::getWeight($this->_id);
         $params = array('id' => $this->_id);
         CRM_Core_BAO_UFGroup::retrieve($params, $defaults);
         $defaults['group'] = $defaults['limit_listings_group_id'];
         //get the uf join records for current uf group
         $ufJoinRecords = CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_id);
         foreach ($ufJoinRecords as $key => $value) {
             $checked[$value] = 1;
         }
         $defaults['uf_group_type'] = $checked;
         //get the uf join records for current uf group other than default modules
         $otherModules = array();
         $otherModules = CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_id, true, true);
         if (!empty($otherModules)) {
             foreach ($otherModules as $key) {
                 $otherModuleString .= " [ x ] " . $key;
             }
             $this->assign('otherModuleString', $otherModuleString);
         }
     } else {
         $defaults['is_active'] = 1;
     }
     return $defaults;
 }
示例#10
0
文件: Field.php 项目: kidaa30/yes
 /**
  * Browse all CiviCRM Profile group fields.
  *
  * @return void
  */
 public function browse()
 {
     $resourceManager = CRM_Core_Resources::singleton();
     if (!empty($_GET['new']) && $resourceManager->ajaxPopupsEnabled) {
         $resourceManager->addScriptFile('civicrm', 'js/crm.addNew.js', 999, 'html-header');
     }
     $ufField = array();
     $ufFieldBAO = new CRM_Core_BAO_UFField();
     // fkey is gid
     $ufFieldBAO->uf_group_id = $this->_gid;
     $ufFieldBAO->orderBy('weight', 'field_name');
     $ufFieldBAO->find();
     $otherModules = CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_gid);
     $this->assign('otherModules', $otherModules);
     $isGroupReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'is_reserved');
     $this->assign('isGroupReserved', $isGroupReserved);
     $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid);
     if ($profileType == 'Contribution' || $profileType == 'Membership' || $profileType == 'Activity' || $profileType == 'Participant') {
         $this->assign('skipCreate', TRUE);
     }
     $locationType = array();
     $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     $fields = CRM_Contact_BAO_Contact::exportableFields('All', FALSE, TRUE);
     $fields = array_merge(CRM_Contribute_BAO_Contribution::getContributionFields(), $fields);
     $select = array();
     foreach ($fields as $name => $field) {
         if ($name) {
             $select[$name] = $field['title'];
         }
     }
     $select['group'] = ts('Group(s)');
     $select['tag'] = ts('Tag(s)');
     $visibility = CRM_Core_SelectValues::ufVisibility();
     while ($ufFieldBAO->fetch()) {
         $ufField[$ufFieldBAO->id] = array();
         $phoneType = $locType = '';
         CRM_Core_DAO::storeValues($ufFieldBAO, $ufField[$ufFieldBAO->id]);
         $ufField[$ufFieldBAO->id]['visibility_display'] = $visibility[$ufFieldBAO->visibility];
         $ufField[$ufFieldBAO->id]['label'] = $ufFieldBAO->label;
         $action = array_sum(array_keys($this->actionLinks()));
         if ($ufFieldBAO->is_active) {
             $action -= CRM_Core_Action::ENABLE;
         } else {
             $action -= CRM_Core_Action::DISABLE;
         }
         if ($ufFieldBAO->is_reserved) {
             $action -= CRM_Core_Action::UPDATE;
             $action -= CRM_Core_Action::DISABLE;
             $action -= CRM_Core_Action::DELETE;
         }
         $ufField[$ufFieldBAO->id]['order'] = $ufField[$ufFieldBAO->id]['weight'];
         $ufField[$ufFieldBAO->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $ufFieldBAO->id, 'gid' => $this->_gid), ts('more'), FALSE, 'ufField.row.actions', 'UFField', $ufFieldBAO->id);
     }
     $returnURL = CRM_Utils_System::url('civicrm/admin/uf/group/field', "reset=1&action=browse&gid={$this->_gid}");
     $filter = "uf_group_id = {$this->_gid}";
     CRM_Utils_Weight::addOrder($ufField, 'CRM_Core_DAO_UFField', 'id', $returnURL, $filter);
     $this->assign('ufField', $ufField);
     // retrieve showBestResult from session
     $session = CRM_Core_Session::singleton();
     $showBestResult = $session->get('showBestResult');
     $this->assign('showBestResult', $showBestResult);
     $session->set('showBestResult', 0);
 }
 /**
  * Browse all CiviCRM Profile group fields.
  *
  * @return void
  * @access public
  * @static
  */
 function browse()
 {
     $ufField = array();
     $ufFieldBAO = new CRM_Core_BAO_UFField();
     // fkey is gid
     $ufFieldBAO->uf_group_id = $this->_gid;
     $ufFieldBAO->orderBy('weight', 'field_name');
     $ufFieldBAO->find();
     $otherModules = CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_gid);
     $this->assign('otherModules', $otherModules);
     $isGroupReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'is_reserved');
     $this->assign('isGroupReserved', $isGroupReserved);
     $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid);
     if ($profileType == 'Contribution' || $profileType == 'Membership' || $profileType == 'Activity' || $profileType == 'Participant') {
         $this->assign('skipCreate', TRUE);
     }
     $locationType = array();
     $locationType = CRM_Core_PseudoConstant::locationType();
     $fields = CRM_Contact_BAO_Contact::exportableFields('All', FALSE, TRUE);
     $fields = array_merge(CRM_Contribute_BAO_Contribution::getContributionFields(), $fields);
     if (CRM_Core_Permission::access('Quest')) {
         $fields = array_merge(CRM_Quest_BAO_Student::exportableFields(), $fields);
     }
     $select = array();
     foreach ($fields as $name => $field) {
         if ($name) {
             $select[$name] = $field['title'];
         }
     }
     $select['group'] = ts('Group(s)');
     $select['tag'] = ts('Tag(s)');
     while ($ufFieldBAO->fetch()) {
         $ufField[$ufFieldBAO->id] = array();
         $phoneType = $locType = '';
         CRM_Core_DAO::storeValues($ufFieldBAO, $ufField[$ufFieldBAO->id]);
         CRM_Core_DAO_UFField::addDisplayEnums($ufField[$ufFieldBAO->id]);
         $ufField[$ufFieldBAO->id]['label'] = $ufFieldBAO->label;
         $action = array_sum(array_keys($this->actionLinks()));
         if ($ufFieldBAO->is_active) {
             $action -= CRM_Core_Action::ENABLE;
         } else {
             $action -= CRM_Core_Action::DISABLE;
         }
         if ($ufFieldBAO->is_reserved) {
             $action -= CRM_Core_Action::UPDATE;
             $action -= CRM_Core_Action::DISABLE;
             $action -= CRM_Core_Action::DELETE;
         }
         $ufField[$ufFieldBAO->id]['order'] = $ufField[$ufFieldBAO->id]['weight'];
         $ufField[$ufFieldBAO->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $ufFieldBAO->id, 'gid' => $this->_gid));
     }
     $returnURL = CRM_Utils_System::url('civicrm/admin/uf/group/field', "reset=1&action=browse&gid={$this->_gid}");
     $filter = "uf_group_id = {$this->_gid}";
     CRM_Utils_Weight::addOrder($ufField, 'CRM_Core_DAO_UFField', 'id', $returnURL, $filter);
     $this->assign('ufField', $ufField);
     // retrieve showBestResult from session
     $session = CRM_Core_Session::singleton();
     $showBestResult = $session->get('showBestResult');
     $this->assign('showBestResult', $showBestResult);
     $session->set('showBestResult', 0);
 }
示例#12
0
文件: Group.php 项目: bhirsch/voipdev
 /**
  * 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);
 }
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Profile Field'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if (isset($this->_id)) {
         $params = array('id' => $this->_id);
         CRM_Core_BAO_UFField::retrieve($params, $defaults);
         // set it to null if so (avoids crappy E_NOTICE errors below
         $defaults['location_type_id'] = CRM_Utils_Array::value('location_type_id', $defaults);
         $specialFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'geo_code_1', 'geo_code_2', 'state_province', 'country', 'county', 'phone', 'email', 'im', 'address_name');
         if (!$defaults['location_type_id'] && $defaults["field_type"] != "Formatting" && in_array($defaults['field_name'], $specialFields)) {
             $defaults['location_type_id'] = 0;
         }
         $defaults['field_name'] = array($defaults['field_type'], $defaults['field_type'] == "Formatting" ? "" : $defaults['field_name'], $defaults['location_type_id'], CRM_Utils_Array::value('phone_type_id', $defaults));
         $this->_gid = $defaults['uf_group_id'];
     } else {
         $defaults['is_active'] = 1;
     }
     $otherModules = array_values(CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_gid));
     $this->assign('otherModules', $otherModules);
     if ($this->_action & CRM_Core_Action::ADD) {
         $fieldValues = array('uf_group_id' => $this->_gid);
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_UFField', $fieldValues);
     }
     // lets trim all the whitespace
     $this->applyFilter('__ALL__', 'trim');
     //hidden field to catch the group id in profile
     $this->add('hidden', 'group_id', $this->_gid);
     //hidden field to catch the field id in profile
     $this->add('hidden', 'field_id', $this->_id);
     $fields = array();
     $fields['Individual'] = CRM_Contact_BAO_Contact::importableFields('Individual', FALSE, FALSE, TRUE);
     $fields['Household'] = CRM_Contact_BAO_Contact::importableFields('Household', FALSE, FALSE, TRUE);
     $fields['Organization'] = CRM_Contact_BAO_Contact::importableFields('Organization', FALSE, FALSE, TRUE);
     // add current employer for individuals
     $fields['Individual']['current_employer'] = array('name' => 'organization_name', 'title' => ts('Current Employer'));
     $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE);
     if (!$addressOptions['county']) {
         unset($fields['Individual']['county']);
         unset($fields['Household']['county']);
         unset($fields['Organization']['county']);
     }
     $fields['Contact'] = array();
     //build the common contact fields array CRM-3037.
     foreach ($fields['Individual'] as $key => $value) {
         if (CRM_Utils_Array::value($key, $fields['Household']) && CRM_Utils_Array::value($key, $fields['Organization'])) {
             $fields['Contact'][$key] = $value;
             //as we move common fields to contacts. There fore these fields
             //are unset from resoective array's.
             unset($fields['Individual'][$key]);
             unset($fields['Household'][$key]);
             unset($fields['Organization'][$key]);
         }
     }
     // add current employer for individuals
     $fields['Contact']['id'] = array('name' => 'id', 'title' => ts('Internal Contact ID'));
     unset($fields['Contact']['contact_type']);
     // since we need a hierarchical list to display contact types & subtypes,
     // this is what we going to display in first selector
     $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, FALSE);
     unset($contactTypes['']);
     // include Subtypes For Profile
     $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo();
     foreach ($subTypes as $name => $val) {
         //custom fields for sub type
         $subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($name);
         if (array_key_exists($val['parent'], $fields)) {
             $fields[$name] = $fields[$val['parent']] + $subTypeFields;
         } else {
             $fields[$name] = $subTypeFields;
         }
     }
     //group selected and unwanted fields list
     $groupFieldList = array_merge(CRM_Core_BAO_UFGroup::getFields($this->_gid, FALSE, NULL, NULL, NULL, TRUE, NULL, TRUE), array('note', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'id'));
     //unset selected fields
     foreach ($groupFieldList as $key => $value) {
         if (is_integer($key)) {
             unset($fields['Individual'][$value], $fields['Household'][$value], $fields['Organization'][$value]);
             continue;
         }
         if (CRM_Utils_Array::value('field_name', $defaults) && $defaults['field_name']['0'] == $value['field_type'] && $defaults['field_name']['1'] == $key) {
             continue;
         }
         unset($fields[$value['field_type']][$key]);
     }
     unset($subTypes);
     if (CRM_Core_Permission::access('Quest')) {
         $fields['Student'] = CRM_Quest_BAO_Student::exportableFields();
     }
     // add current employer for individuals
     $fields['Contact']['id'] = array('name' => 'id', 'title' => ts('Internal Contact ID'));
     if (CRM_Core_Permission::access('CiviContribute')) {
         $contribFields = CRM_Contribute_BAO_Contribution::getContributionFields(FALSE);
         if (!empty($contribFields)) {
             unset($contribFields['is_test']);
             unset($contribFields['is_pay_later']);
             unset($contribFields['contribution_id']);
             if ($this->_gid && CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'name') == 'contribution_batch_entry') {
                 $fields['Contribution'] =& array_merge($contribFields, $this->_contriBatchEntryFields);
             } else {
                 $fields['Contribution'] =& $contribFields;
             }
         }
     }
     if (CRM_Core_Permission::access('CiviEvent')) {
         $participantFields = CRM_Event_BAO_Query::getParticipantFields(TRUE);
         if (!empty($participantFields)) {
             unset($participantFields['external_identifier']);
             unset($participantFields['event_id']);
             unset($participantFields['participant_contact_id']);
             unset($participantFields['participant_role_id']);
             unset($participantFields['participant_status_id']);
             unset($participantFields['participant_is_test']);
             unset($participantFields['participant_fee_level']);
             unset($participantFields['participant_id']);
             unset($participantFields['participant_is_pay_later']);
             if (isset($participantFields['participant_campaign_id'])) {
                 $participantFields['participant_campaign_id']['title'] = ts('Campaign');
                 if (isset($participantFields['participant_campaign'])) {
                     unset($participantFields['participant_campaign']);
                 }
             }
             $fields['Participant'] =& $participantFields;
         }
     }
     if (CRM_Core_Permission::access('CiviMember')) {
         $membershipFields = CRM_Member_BAO_Membership::getMembershipFields();
         unset($membershipFields['membership_id']);
         //unset( $membershipFields['join_date'] );
         //unset( $membershipFields['membership_start_date'] );
         unset($membershipFields['membership_type_id']);
         //unset( $membershipFields['membership_end_date'] );
         unset($membershipFields['member_is_test']);
         unset($membershipFields['is_override']);
         unset($membershipFields['status_id']);
         unset($membershipFields['member_is_pay_later']);
         if ($this->_gid && CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'name') == 'membership_batch_entry') {
             $fields['Membership'] =& array_merge($membershipFields, $this->_memberBatchEntryFields);
         } else {
             $fields['Membership'] =& $membershipFields;
         }
     }
     $activityFields = CRM_Activity_BAO_Activity::getProfileFields();
     if (!empty($activityFields)) {
         //unset campaign related fields.
         if (isset($activityFields['activity_campaign_id'])) {
             $activityFields['activity_campaign_id']['title'] = ts('Campaign');
         }
         $fields['Activity'] = $activityFields;
     }
     $formattingFields["format_free_html_" . rand(1000, 9999)] = array("name" => "free_html", "import" => FALSE, "export" => FALSE, "title" => "Free HTML");
     $fields["Formatting"] = $formattingFields;
     $noSearchable = array();
     $addressCustomFields = array_keys(CRM_Core_BAO_CustomField::getFieldsForImport('Address'));
     foreach ($fields as $key => $value) {
         foreach ($value as $key1 => $value1) {
             //CRM-2676, replacing the conflict for same custom field name from different custom group.
             if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key1)) {
                 $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $customFieldId, 'custom_group_id');
                 $customGroupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'title');
                 $this->_mapperFields[$key][$key1] = $value1['title'] . ' :: ' . $customGroupName;
                 if (in_array($key1, $addressCustomFields)) {
                     $noSearchable[] = $value1['title'] . ' :: ' . $customGroupName;
                 }
             } else {
                 $this->_mapperFields[$key][$key1] = $value1['title'];
             }
             $hasLocationTypes[$key][$key1] = CRM_Utils_Array::value('hasLocationType', $value1);
             // hide the 'is searchable' field for 'File' custom data
             if (isset($value1['data_type']) && isset($value1['html_type']) && ($value1['data_type'] == 'File' && $value1['html_type'] == 'File' || $value1['data_type'] == 'Link' && $value1['html_type'] == 'Link')) {
                 if (!in_array($value1['title'], $noSearchable)) {
                     $noSearchable[] = $value1['title'];
                 }
             }
         }
     }
     $this->assign('noSearchable', $noSearchable);
     $this->_location_types = CRM_Core_PseudoConstant::locationType();
     $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
     /* FIXME: dirty hack to make the default option show up first.  This
      * avoids a mozilla browser bug with defaults on dynamically constructed
      * selector widgets. */
     if ($defaultLocationType) {
         $defaultLocation = $this->_location_types[$defaultLocationType->id];
         unset($this->_location_types[$defaultLocationType->id]);
         $this->_location_types = array($defaultLocationType->id => $defaultLocation) + $this->_location_types;
     }
     $this->_location_types = array('Primary') + $this->_location_types;
     $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array();
     $sel1 = array('' => '- select -') + $contactTypes;
     if (CRM_Core_Permission::access('Quest')) {
         $sel1['Student'] = 'Students';
     }
     if (!empty($activityFields)) {
         $sel1['Activity'] = 'Activity';
     }
     if (CRM_Core_Permission::access('CiviEvent')) {
         $sel1['Participant'] = 'Participants';
     }
     if (!empty($contribFields)) {
         $sel1['Contribution'] = 'Contributions';
     }
     if (!empty($membershipFields)) {
         $sel1['Membership'] = 'Membership';
     }
     if (!empty($formattingFields)) {
         $sel1['Formatting'] = 'Formatting';
     }
     foreach ($sel1 as $key => $sel) {
         if ($key) {
             $sel2[$key] = $this->_mapperFields[$key];
         }
     }
     $sel3[''] = NULL;
     $phoneTypes = CRM_Core_PseudoConstant::phoneType();
     ksort($phoneTypes);
     foreach ($sel1 as $k => $sel) {
         if ($k) {
             foreach ($this->_location_types as $key => $value) {
                 $sel4[$k]['phone'][$key] =& $phoneTypes;
             }
         }
     }
     foreach ($sel1 as $k => $sel) {
         if ($k) {
             if (is_array($this->_mapperFields[$k])) {
                 foreach ($this->_mapperFields[$k] as $key => $value) {
                     if ($hasLocationTypes[$k][$key]) {
                         $sel3[$k][$key] = $this->_location_types;
                     } else {
                         $sel3[$key] = NULL;
                     }
                 }
             }
         }
     }
     $this->_defaults = array();
     $js = "<script type='text/javascript'>\n";
     $formName = "document.{$this->_name}";
     $alreadyMixProfile = FALSE;
     if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) {
         $alreadyMixProfile = TRUE;
     }
     $this->assign('alreadyMixProfile', $alreadyMixProfile);
     $extra = array('onclick' => 'showLabel();mixProfile();', 'onblur' => 'showLabel();mixProfile();');
     $sel =& $this->addElement('hierselect', 'field_name', ts('Field Name'), $extra);
     $formValues = array();
     $formValues = $this->exportValues();
     if (empty($formValues)) {
         for ($k = 1; $k < 4; $k++) {
             if (!$defaults['field_name'][$k]) {
                 $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n";
             }
         }
     } else {
         if (!empty($formValues['field_name'])) {
             foreach ($formValues['field_name'] as $value) {
                 for ($k = 1; $k < 4; $k++) {
                     if (!isset($formValues['field_name'][$k]) || !$formValues['field_name'][$k]) {
                         $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n";
                     } else {
                         $js .= "{$formName}['field_name[{$k}]'].style.display = '';\n";
                     }
                 }
             }
         } else {
             for ($k = 1; $k < 4; $k++) {
                 if (!isset($defaults['field_name'][$k])) {
                     $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n";
                 }
             }
         }
     }
     foreach ($sel2 as $k => $v) {
         if (is_array($sel2[$k])) {
             asort($sel2[$k]);
         }
     }
     $sel->setOptions(array($sel1, $sel2, $sel3, $sel4));
     $visibleValues = array();
     if (in_array('Search Profile', $otherModules)) {
         $visibleValues['Public Pages and Listings'] = 'Public Pages and Listings';
     } else {
         $visibleValues = CRM_Core_SelectValues::ufVisibility();
     }
     $js .= "</script>\n";
     $this->assign('initHideBoxes', $js);
     $this->add('select', 'visibility', ts('Visibility'), $visibleValues, TRUE, array('onChange' => "showHideSeletorSearch(this.value);"));
     //CRM-4363
     $js = array('onclick' => "mixProfile();");
     // should the field appear in selectors (as a column)?
     $this->add('checkbox', 'in_selector', ts('Results Column?'), NULL, NULL, $js);
     $this->add('checkbox', 'is_searchable', ts('Searchable?'), NULL, NULL, $js);
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField');
     // weight
     $this->add('text', 'weight', ts('Order'), $attributes['weight'], TRUE);
     $this->addRule('weight', ts('is a numeric field'), 'numeric');
     $this->add('textarea', 'help_pre', ts('Field Pre Help'), $attributes['help_pre']);
     $this->add('textarea', 'help_post', ts('Field Post Help'), $attributes['help_post']);
     $this->add('checkbox', 'is_required', ts('Required?'));
     $this->add('checkbox', 'is_active', ts('Active?'));
     $this->add('checkbox', 'is_view', ts('View Only?'));
     // $this->add( 'checkbox', 'is_registration', ts( 'Display in Registration Form?' ) );
     //$this->add( 'checkbox', 'is_match'       , ts( 'Key to Match Contacts?'        ) );
     $this->add('text', 'label', ts('Field Label'), $attributes['label']);
     $js = NULL;
     if ($this->_hasSearchableORInSelector) {
         $js = array('onclick' => "return verify( );");
     }
     // add buttons
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE, 'js' => $js), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $js), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->addFormRule(array('CRM_UF_Form_Field', 'formRule'), $this);
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
         $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/uf/group/field?reset=1&action=browse&gid=" . $this->_gid . "'"));
     }
     if (isset($defaults['field_name']) && CRM_Utils_Array::value(1, $defaults['field_name']) == 'url-1') {
         $defaults['field_name'][1] = 'url';
     }
     $this->setDefaults($defaults);
 }