Example #1
0
 /**
  * pre processing work done here.
  *
  * gets session variables for group or field id
  *
  * @param
  * @return void
  *
  * @access public
  *
  */
 function preProcess()
 {
     $flag = false;
     $this->_gid = $this->get('id');
     $this->set('gid', $this->_gid);
     $field = CRM_Utils_Request::retrieve('field', 'Boolean', $this, true, 0);
     if ($field) {
         $this->_fields = CRM_Core_BAO_UFGroup::getFields($this->_gid, false, null, null, null, true);
         require_once 'CRM/Core/DAO/UFField.php';
         $fieldDAO = new CRM_Core_DAO_UFField();
         $fieldDAO->id = $this->get('fieldId');
         $fieldDAO->find(true);
         if ($fieldDAO->is_active == 0) {
             CRM_Core_Error::statusBounce(ts('This field is inactive so it will not be displayed on profile form.'));
         } elseif ($fieldDAO->is_view == 1) {
             CRM_Core_Error::statusBounce(ts('This field is view only so it will not be displayed on profile form.'));
         }
         $name = $fieldDAO->field_name;
         // preview for field
         $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');
         if ($fieldDAO->location_type_id) {
             $name .= '-' . $fieldDAO->location_type_id;
         } else {
             if (in_array($name, $specialFields)) {
                 $name .= '-Primary';
             }
         }
         if (isset($fieldDAO->phone_type)) {
             $name .= '-' . $fieldDAO->phone_type;
         }
         $fieldArray[$name] = $this->_fields[$name];
         $this->_fields = $fieldArray;
         if (!is_array($this->_fields[$name])) {
             $flag = true;
         }
         $this->assign('previewField', true);
     } else {
         $this->_fields = CRM_Core_BAO_UFGroup::getFields($this->_gid);
     }
     if ($flag) {
         $this->assign('viewOnly', false);
     } else {
         $this->assign('viewOnly', true);
     }
     $this->set('fieldId', null);
     $this->assign("fields", $this->_fields);
 }
Example #2
0
 /**
  * Pre processing work done here.
  *
  * gets session variables for group or field id
  *
  * @param
  *
  * @return void
  */
 public function preProcess()
 {
     $flag = FALSE;
     $gid = $this->get('id');
     $this->set('gid', $gid);
     $field = CRM_Utils_Request::retrieve('field', 'Boolean', $this, TRUE, 0);
     if ($field) {
         $fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, NULL, NULL, NULL, TRUE);
         $fieldDAO = new CRM_Core_DAO_UFField();
         $fieldDAO->id = $this->get('fieldId');
         $fieldDAO->find(TRUE);
         if ($fieldDAO->is_active == 0) {
             CRM_Core_Error::statusBounce(ts('This field is inactive so it will not be displayed on profile form.'));
         } elseif ($fieldDAO->is_view == 1) {
             CRM_Core_Error::statusBounce(ts('This field is view only so it will not be displayed on profile form.'));
         }
         $name = $fieldDAO->field_name;
         if ($fieldDAO->field_name == 'phone_and_ext') {
             $name = 'phone';
         }
         // preview for field
         $specialFields = array('address_name', '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');
         if ($fieldDAO->location_type_id) {
             $name .= '-' . $fieldDAO->location_type_id;
         } elseif (in_array($name, $specialFields)) {
             $name .= '-Primary';
         }
         if (isset($fieldDAO->phone_type_id)) {
             $name .= '-' . $fieldDAO->phone_type_id;
         }
         $fieldArray[$name] = $fields[$name];
         if ($fieldDAO->field_name == 'phone_and_ext') {
             $phoneExtField = str_replace('phone', 'phone_ext', $name);
             $fieldArray[$phoneExtField] = $fields[$phoneExtField];
         }
         $fields = $fieldArray;
         if (!is_array($fields[$name])) {
             $flag = TRUE;
         }
         $this->setProfile($fields, TRUE, $flag);
     } else {
         $fields = CRM_Core_BAO_UFGroup::getFields($gid);
         $this->setProfile($fields);
     }
 }
Example #3
0
 /**
  * Delete profile field given a custom field.
  *
  * @param int $customFieldId
  *   ID of the custom field to be deleted.
  *
  * @return void
  *
  */
 public static function delUFField($customFieldId)
 {
     //find the profile id given custom field id
     $ufField = new CRM_Core_DAO_UFField();
     $ufField->field_name = "custom_" . $customFieldId;
     $ufField->find();
     while ($ufField->fetch()) {
         //enable/ disable profile
         CRM_Core_BAO_UFField::del($ufField->id);
     }
 }
Example #4
0
 /**
  * Delete the profile Group.
  *
  * @param int $id
  *   Profile Id.
  *
  * @return bool
  *
  */
 public static function del($id)
 {
     //check whether this group contains  any profile fields
     $profileField = new CRM_Core_DAO_UFField();
     $profileField->uf_group_id = $id;
     $profileField->find();
     while ($profileField->fetch()) {
         CRM_Core_BAO_UFField::del($profileField->id);
     }
     //delete records from uf join table
     $ufJoin = new CRM_Core_DAO_UFJoin();
     $ufJoin->uf_group_id = $id;
     $ufJoin->delete();
     //delete profile group
     $group = new CRM_Core_DAO_UFGroup();
     $group->id = $id;
     $group->delete();
     return 1;
 }
Example #5
0
 /**
  * adds $value['foo_display'] for each $value['foo'] enum from civicrm_uf_field
  *
  * @param array $values (reference)  the array up for enhancing
  * @return void
  */
 static function addDisplayEnums(&$values)
 {
     $enumFields =& CRM_Core_DAO_UFField::getEnums();
     foreach ($enumFields as $enum) {
         if (isset($values[$enum])) {
             $values[$enum . '_display'] = CRM_Core_DAO_UFField::tsEnum($enum, $values[$enum]);
         }
     }
 }
Example #6
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();
     require_once "CRM/Core/BAO/UFField.php";
     $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();
     require_once 'CRM/Contact/BAO/Contact.php';
     $fields =& CRM_Contact_BAO_Contact::exportableFields('All', false, true);
     require_once "CRM/Contribute/BAO/Contribution.php";
     $fields = array_merge(CRM_Contribute_BAO_Contribution::getContributionFields(), $fields);
     if (CRM_Core_Permission::access('Quest')) {
         require_once 'CRM/Quest/BAO/Student.php';
         $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}";
     require_once 'CRM/Utils/Weight.php';
     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);
 }
Example #7
0
 /**
  * Process the form.
  *
  * @return void
  */
 public function postProcess()
 {
     $ids = array('uf_group' => $this->_gid);
     if ($this->_action & CRM_Core_Action::DELETE) {
         $fieldValues = array('uf_group_id' => $this->_gid);
         CRM_Utils_Weight::delWeight('CRM_Core_DAO_UFField', $this->_id, $fieldValues);
         $deleted = CRM_Core_BAO_UFField::del($this->_id);
         //update group_type every time. CRM-3608
         if ($this->_gid && $deleted) {
             //get the profile type.
             $fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($this->_gid, TRUE);
             CRM_Core_BAO_UFGroup::updateGroupTypes($this->_gid, $fieldsType);
         }
         CRM_Core_Session::setStatus(ts('Selected Profile Field has been deleted.'), ts('Profile Field Deleted'), 'success');
         return;
     }
     // store the submitted values in an array
     $params = $this->controller->exportValues('Field');
     if ($params['visibility'] == 'User and User Admin Only') {
         $params['is_searchable'] = $params['in_selector'] = 0;
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $ids['uf_field'] = $this->_id;
     }
     $name = NULL;
     if (isset($params['field_name'][1]) && isset($this->_selectFields[$params['field_name'][1]])) {
         // we dont get a name for a html formatting element
         $name = $this->_selectFields[$params['field_name'][1]];
     }
     //Hack for Formatting Field Name
     if ($params['field_name'][0] == 'Formatting') {
         $params['field_name'][1] = 'formatting_' . rand(1000, 9999);
     }
     //check for duplicate fields
     if ($params["field_name"][0] != "Formatting" && CRM_Core_BAO_UFField::duplicateField($params, $ids)) {
         CRM_Core_Session::setStatus(ts('The selected field already exists in this profile.'), ts('Field Not Added'), 'error');
         return;
     } else {
         $params['weight'] = CRM_Core_BAO_UFField::autoWeight($params);
         $ufField = CRM_Core_BAO_UFField::add($params, $ids);
         //reset other field is searchable and in selector settings, CRM-4363
         if ($this->_hasSearchableORInSelector && in_array($ufField->field_type, array('Participant', 'Contribution', 'Membership', 'Activity', 'Case'))) {
             CRM_Core_BAO_UFField::resetInSelectorANDSearchable($this->_gid);
         }
         $config = CRM_Core_Config::singleton();
         $showBestResult = FALSE;
         if (in_array($ufField->field_name, array('country', 'state_province')) && count($config->countryLimit) > 1) {
             // get state or country field weight if exists
             $field = 'state_province';
             if ($ufField->field_name == 'state_province') {
                 $field = 'country';
             }
             $ufFieldDAO = new CRM_Core_DAO_UFField();
             $ufFieldDAO->field_name = $field;
             $ufFieldDAO->location_type_id = $ufField->location_type_id;
             $ufFieldDAO->uf_group_id = $ufField->uf_group_id;
             if ($ufFieldDAO->find(TRUE)) {
                 if ($field == 'country' && $ufFieldDAO->weight > $ufField->weight) {
                     $showBestResult = TRUE;
                 } elseif ($field == 'state_province' && $ufFieldDAO->weight < $ufField->weight) {
                     $showBestResult = TRUE;
                 }
             }
         }
         //update group_type every time. CRM-3608
         if ($this->_gid && is_a($ufField, 'CRM_Core_DAO_UFField')) {
             // get the profile type.
             $fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($this->_gid, TRUE);
             CRM_Core_BAO_UFGroup::updateGroupTypes($this->_gid, $fieldsType);
         }
         CRM_Core_Session::setStatus(ts('Your CiviCRM Profile Field \'%1\' has been saved to \'%2\'.', array(1 => $name, 2 => $this->_title)), ts('Profile Field Saved'), 'success');
     }
     $buttonName = $this->controller->getButtonName();
     $session = CRM_Core_Session::singleton();
     if ($buttonName == $this->getButtonName('next', 'new')) {
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/uf/group/field/add', "reset=1&action=add&gid={$this->_gid}&sbr={$showBestResult}"));
     } else {
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/uf/group/field', "reset=1&action=browse&gid={$this->_gid}"));
         $session->set('showBestResult', $showBestResult);
     }
 }
Example #8
0
 /**
  * Returns the list of fields that can be exported
  *
  * @param bool $prefix
  *
  * @return array
  */
 static function &export($prefix = false)
 {
     if (!self::$_export) {
         self::$_export = array();
         $fields = self::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     self::$_export['uf_field'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }
Example #9
0
 /**
  * Process the form
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $ids = array('uf_group' => $this->_gid);
     if ($this->_action & CRM_Core_Action::DELETE) {
         $fieldValues = array('uf_group_id' => $this->_gid);
         $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_UFField', $this->_id, $fieldValues);
         $deleted = CRM_Core_BAO_UFField::del($this->_id);
         //update group_type every time. CRM-3608
         if ($this->_gid && $deleted) {
             //get the profile type.
             $groupType = 'null';
             $fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($this->_gid);
             if (!empty($fieldsType)) {
                 $groupType = implode(',', $fieldsType);
             }
             //set group type
             CRM_Core_DAO::setFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'group_type', $groupType);
         }
         CRM_Core_Session::setStatus(ts('Selected Profile Field has been deleted.'));
         return;
     }
     // store the submitted values in an array
     $params = $this->controller->exportValues('Field');
     if ($params['visibility'] == 'User and User Admin Only') {
         $params['is_searchable'] = $params['in_selector'] = 0;
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $ids['uf_field'] = $this->_id;
     }
     // temporary hack to for website
     if ($params['field_name'][1] == 'url') {
         $params['field_name'][1] = 'url-1';
     }
     //check for duplicate fields
     if (CRM_Core_BAO_UFField::duplicateField($params, $ids)) {
         CRM_Core_Session::setStatus(ts('The selected field was not added. It already exists in this profile.'));
         return;
     } else {
         $ufField = CRM_Core_BAO_UFField::add($params, $ids);
         $name = $this->_selectFields[$ufField->field_name];
         //reset other field is searchable and in selector settings, CRM-4363
         if ($this->_hasSearchableORInSelector && in_array($ufField->field_type, array('Participant', 'Contribution', 'Membership', 'Activity'))) {
             CRM_Core_BAO_UFField::resetInSelectorANDSearchable($this->_gid);
         }
         $config = CRM_Core_Config::singleton();
         $showBestResult = false;
         if (in_array($ufField->field_name, array('country', 'state_province')) && count($config->countryLimit) > 1) {
             // get state or country field weight if exists
             $field = 'state_province';
             if ($ufField->field_name == 'state_province') {
                 $field = 'country';
             }
             $ufFieldDAO = new CRM_Core_DAO_UFField();
             $ufFieldDAO->field_name = $field;
             $ufFieldDAO->location_type_id = $ufField->location_type_id;
             $ufFieldDAO->uf_group_id = $ufField->uf_group_id;
             if ($ufFieldDAO->find(true)) {
                 if ($field == 'country' && $ufFieldDAO->weight > $ufField->weight) {
                     $showBestResult = true;
                 } elseif ($field == 'state_province' && $ufFieldDAO->weight < $ufField->weight) {
                     $showBestResult = true;
                 }
             }
         }
         //update group_type every time. CRM-3608
         if ($this->_gid && is_a($ufField, 'CRM_Core_DAO_UFField')) {
             //get the profile type.
             $groupType = 'null';
             $fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($this->_gid);
             if (!empty($fieldsType)) {
                 $groupType = implode(',', $fieldsType);
             }
             //set group type
             CRM_Core_DAO::setFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'group_type', $groupType);
         }
         CRM_Core_Session::setStatus(ts('Your CiviCRM Profile Field \'%1\' has been saved to \'%2\'.', array(1 => $name, 2 => $this->_title)));
     }
     $buttonName = $this->controller->getButtonName();
     $session = CRM_Core_Session::singleton();
     if ($buttonName == $this->getButtonName('next', 'new')) {
         CRM_Core_Session::setStatus(ts(' You can add another profile field.'));
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/uf/group/field/add', "reset=1&action=add&gid={$this->_gid}&sbr={$showBestResult}"));
     } else {
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/uf/group/field', "reset=1&action=browse&gid={$this->_gid}"));
         $session->set('showBestResult', $showBestResult);
     }
 }
Example #10
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();
     $locationType = array();
     $locationType =& CRM_Core_PseudoConstant::locationType();
     require_once 'CRM/Contact/BAO/Contact.php';
     $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)');
     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]);
         // fix the field_name value
         $ufField[$ufFieldBAO->id]['field_name'] = $select[$ufField[$ufFieldBAO->id]['field_name']];
         if ($ufFieldBAO->location_type_id) {
             $locType = ' (' . $locationType[$ufFieldBAO->location_type_id] . ') ';
         }
         if ($ufFieldBAO->phone_type) {
             if ($ufFieldBAO->phone_type != 'Phone') {
                 // this hack is to prevent Phone Phone
                 $phoneType .= '-' . $ufFieldBAO->phone_type;
             }
         }
         $ufField[$ufFieldBAO->id]['field_name'] .= $phoneType . $locType;
         $action = array_sum(array_keys($this->actionLinks()));
         if ($ufFieldBAO->is_active) {
             $action -= CRM_CORE_ACTION_ENABLE;
         } else {
             $action -= CRM_CORE_ACTION_DISABLE;
         }
         $ufField[$ufFieldBAO->id]['action'] = CRM_Core_Action::formLink(CRM_UF_Page_Field::actionLinks(), $action, array('id' => $ufFieldBAO->id, 'gid' => $this->_gid));
     }
     $this->assign('ufField', $ufField);
 }