/**
  * 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 None
  */
 function setDefaultValues(&$form, &$defaults)
 {
     if (!empty($defaults['preferred_language'])) {
         $languages = array_flip(CRM_Core_PseudoConstant::languages());
         $defaults['preferred_language'] = $languages[$defaults['preferred_language']];
     }
     // CRM-7119: set preferred_language to default if unset
     if (empty($defaults['preferred_language'])) {
         $config = CRM_Core_Config::singleton();
         $defaults['preferred_language'] = $config->lcMessages;
     }
     //set default from greeting types CRM-4575, CRM-9739
     if ($form->_action & CRM_Core_Action::ADD) {
         foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
             if (empty($defaults[$greeting . '_id'])) {
                 if ($defaultGreetingTypeId = CRM_Contact_BAO_Contact_Utils::defaultGreeting($form->_contactType, $greeting)) {
                     $defaults[$greeting . '_id'] = $defaultGreetingTypeId;
                 }
             }
         }
     } else {
         foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
             $name = "{$greeting}_display";
             $form->assign($name, CRM_Utils_Array::value($name, $defaults));
         }
     }
 }
 /**
  * set defaults for the form
  *
  * @return void
  * @access public
  */
 public function setDefaultValues()
 {
     $defaults = array();
     $params = array('id' => $this->_contactId);
     $defaults = array();
     CRM_Contact_BAO_Contact::getValues($params, $defaults);
     $this->_contactType = CRM_Utils_Array::value('contact_type', $defaults);
     if (!empty($defaults['preferred_language'])) {
         $languages = array_flip(CRM_Core_PseudoConstant::languages());
         $defaults['preferred_language'] = $languages[$defaults['preferred_language']];
     }
     // CRM-7119: set preferred_language to default if unset
     if (empty($defaults['preferred_language'])) {
         $config = CRM_Core_Config::singleton();
         $defaults['preferred_language'] = $config->lcMessages;
     }
     foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
         $name = "{$greeting}_display";
         $this->assign($name, CRM_Utils_Array::value($name, $defaults));
     }
     return $defaults;
 }
 /**
  * Function to build profile form
  *
  * @params object  $form       form object
  * @params array   $field      array field properties
  * @params int     $mode       profile mode
  * @params int     $contactID  contact id
  *
  * @return null
  * @static
  * @access public
  */
 static function buildProfile(&$form, &$field, $mode, $contactId = NULL, $online = FALSE, $onBehalf = FALSE, $rowNumber = NULL, $prefix = '')
 {
     $defaultValues = array();
     $fieldName = $field['name'];
     $title = $field['title'];
     $attributes = $field['attributes'];
     $rule = $field['rule'];
     $view = $field['is_view'];
     $required = $mode == CRM_Profile_Form::MODE_SEARCH ? FALSE : $field['is_required'];
     $search = $mode == CRM_Profile_Form::MODE_SEARCH ? TRUE : FALSE;
     $isShared = CRM_Utils_Array::value('is_shared', $field, 0);
     // do not display view fields in drupal registration form
     // CRM-4632
     if ($view && $mode == CRM_Profile_Form::MODE_REGISTER) {
         return;
     }
     if ($onBehalf) {
         $name = "onbehalf[{$fieldName}]";
     } elseif ($contactId && !$online) {
         $name = "field[{$contactId}][{$fieldName}]";
     } elseif ($rowNumber) {
         $name = "field[{$rowNumber}][{$fieldName}]";
     } elseif (!empty($prefix)) {
         $name = $prefix . "[{$fieldName}]";
     } else {
         $name = $fieldName;
     }
     if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) {
         $deleteExtra = ts('Are you sure you want to delete contact image.');
         $deleteURL = array(CRM_Core_Action::DELETE => array('name' => ts('Delete Contact Image'), 'url' => 'civicrm/contact/image', 'qs' => 'reset=1&id=%%id%%&gid=%%gid%%&action=delete', 'extra' => 'onclick = "if (confirm( \'' . $deleteExtra . '\' ) ) this.href+=\'&confirmed=1\'; else return false;"'));
         $deleteURL = CRM_Core_Action::formLink($deleteURL, CRM_Core_Action::DELETE, array('id' => $form->get('id'), 'gid' => $form->get('gid')));
         $form->assign('deleteURL', $deleteURL);
     }
     $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE);
     if (substr($fieldName, 0, 14) === 'state_province') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required);
     } elseif (substr($fieldName, 0, 7) === 'country') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required);
         $config = CRM_Core_Config::singleton();
         if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactCountry) {
             $defaultValues[$name] = $config->defaultContactCountry;
             $form->setDefaults($defaultValues);
         }
     } elseif (substr($fieldName, 0, 6) === 'county') {
         if ($addressOptions['county']) {
             $form->add('select', $name, $title, array('' => ts('- select state -')), $required);
         }
     } elseif (substr($fieldName, 0, 9) === 'image_URL') {
         $form->add('file', $name, $title, $attributes, $required);
         $form->addUploadElement($name);
     } elseif (substr($fieldName, 0, 2) === 'im') {
         $form->add('text', $name, $title, $attributes, $required);
         if (!$contactId) {
             if ($onBehalf) {
                 if (substr($name, -1) == ']') {
                     $providerName = substr($name, 0, -1) . '-provider_id]';
                 }
                 $form->add('select', $providerName, NULL, array('' => ts('- select -')) + CRM_Core_PseudoConstant::IMProvider(), $required);
             } else {
                 $form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::IMProvider(), $required);
             }
             if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) {
                 $form->freeze($name . '-provider_id');
             }
         }
     } elseif ($fieldName === 'birth_date' || $fieldName === 'deceased_date') {
         $form->addDate($name, $title, $required, array('formatType' => 'birth'));
     } elseif (in_array($fieldName, array('membership_start_date', 'membership_end_date', 'join_date'))) {
         $form->addDate($name, $title, $required, array('formatType' => 'custom'));
     } elseif ($field['name'] == 'membership_type') {
         list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo();
         $sel =& $form->addElement('hierselect', $name, $title);
         $select = array('' => ts('- select -'));
         $sel->setOptions(array($select + $orgInfo, $types));
     } elseif ($field['name'] == 'membership_status') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), $required);
     } elseif ($fieldName === 'gender') {
         $genderOptions = array();
         $gender = CRM_Core_PseudoConstant::gender();
         foreach ($gender as $key => $var) {
             $genderOptions[$key] = $form->createElement('radio', NULL, ts('Gender'), $var, $key);
         }
         $form->addGroup($genderOptions, $name, $title);
         if ($required) {
             $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required');
         }
     } elseif ($fieldName === 'individual_prefix') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required);
     } elseif ($fieldName === 'individual_suffix') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required);
     } elseif ($fieldName === 'contact_sub_type') {
         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $form->_fields[$fieldName]);
         if ($onBehalf) {
             $profileType = 'Organization';
         } else {
             $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL;
         }
         $setSubtype = FALSE;
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $setSubtype = $profileType;
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         $subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array();
         if ($setSubtype) {
             $subtypeList = array();
             $subtypeList[$setSubtype] = $subtypes[$setSubtype];
         } else {
             $subtypeList = $subtypes;
         }
         $sel = $form->add('select', $name, $title, $subtypeList, $required);
         $sel->setMultiple(TRUE);
     } elseif (in_array($fieldName, CRM_Contact_BAO_Contact::$_greetingTypes)) {
         //add email greeting, postal greeting, addressee, CRM-4575
         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
         $profileType = CRM_Core_BAO_UFField::getProfileType($gId, TRUE, FALSE, TRUE);
         if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) {
             $profileType = 'Individual';
         }
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         $greeting = array('contact_type' => $profileType, 'greeting_type' => $fieldName);
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($greeting), $required);
         // add custom greeting element
         $form->add('text', $fieldName . '_custom', ts('Custom %1', array(1 => ucwords(str_replace('_', ' ', $fieldName)))), NULL, FALSE);
     } elseif ($fieldName === 'preferred_communication_method') {
         $communicationFields = CRM_Core_PseudoConstant::pcm();
         foreach ($communicationFields as $key => $var) {
             if ($key == '') {
                 continue;
             }
             $communicationOptions[] = $form->createElement('checkbox', $key, NULL, $var);
         }
         $form->addGroup($communicationOptions, $name, $title, '<br/>');
     } elseif ($fieldName === 'preferred_mail_format') {
         $form->add('select', $name, $title, CRM_Core_SelectValues::pmf());
     } elseif ($fieldName === 'preferred_language') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::languages());
     } elseif ($fieldName == 'external_identifier') {
         $form->add('text', $name, $title, $attributes, $required);
         $contID = $contactId;
         if (!$contID) {
             $contID = $form->get('id');
         }
         $form->addRule($name, ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $contID, 'external_identifier'));
     } elseif ($fieldName === 'group') {
         CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, TRUE, $required, $title, NULL, $name);
     } elseif ($fieldName === 'tag') {
         CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::TAG, FALSE, $required, NULL, $title, $name);
     } elseif (substr($fieldName, 0, 4) === 'url-') {
         $form->addElement('text', $name, $title, array_merge(CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), array('onfocus' => "if (!this.value) {  this.value='http://';} else return false", 'onblur' => "if ( this.value == 'http://') {  this.value='';} else return false")));
         $form->addRule($name, ts('Enter a valid Website.'), 'url');
         //Website type select
         if ($onBehalf) {
             if (substr($name, -1) == ']') {
                 $websiteTypeName = substr($name, 0, -1) . '-website_type_id]';
             }
             $form->addElement('select', $websiteTypeName, NULL, CRM_Core_PseudoConstant::websiteType());
         } else {
             $form->addElement('select', $name . '-website_type_id', NULL, CRM_Core_PseudoConstant::websiteType());
         }
         // added because note appeared as a standard text input
     } elseif ($fieldName == 'note') {
         $form->add('textarea', $name, $title, $attributes, $required);
     } elseif (substr($fieldName, 0, 6) === 'custom') {
         $customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName);
         if ($customFieldID) {
             CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title);
         }
     } elseif (substr($fieldName, 0, 14) === 'address_custom') {
         list($fName, $locTypeId) = CRM_Utils_System::explode('-', $fieldName, 2);
         $customFieldID = CRM_Core_BAO_CustomField::getKeyID(substr($fName, 8));
         if ($customFieldID) {
             CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title);
         }
     } elseif (in_array($fieldName, array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) {
         $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
     } elseif ($fieldName == 'send_receipt') {
         $form->addElement('checkbox', $name, $title);
     } elseif ($fieldName == 'soft_credit') {
         CRM_Contact_Form_NewContact::buildQuickForm($form, $rowNumber, NULL, FALSE, 'soft_credit_');
     } elseif ($fieldName == 'product_name') {
         list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo();
         $sel =& $form->addElement('hierselect', $name, $title);
         $products = array('0' => ts('- select -')) + $products;
         $sel->setOptions(array($products, $options));
     } elseif ($fieldName == 'payment_instrument') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required);
     } elseif ($fieldName == 'contribution_type') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType(), $required);
     } elseif ($fieldName == 'contribution_status_id') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionStatus(), $required);
     } elseif ($fieldName == 'currency') {
         $form->addCurrency($name, $title, $required);
     } elseif ($fieldName == 'contribution_page_id') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage(), $required, 'class="big"');
     } elseif ($fieldName == 'participant_register_date') {
         $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
     } elseif ($fieldName == 'activity_status_id') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::activityStatus(), $required);
     } elseif ($fieldName == 'activity_engagement_level') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Campaign_PseudoConstant::engagementLevel(), $required);
     } elseif ($fieldName == 'activity_date_time') {
         $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
     } elseif ($fieldName == 'participant_status') {
         $cond = NULL;
         if ($online == TRUE) {
             $cond = 'visibility_id = 1';
         }
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(NULL, $cond, 'label'), $required);
     } elseif ($fieldName == 'participant_role') {
         if (CRM_Utils_Array::value('is_multiple', $field)) {
             $form->addCheckBox($name, $title, CRM_Event_PseudoConstant::participantRole(), NULL, NULL, NULL, NULL, '&nbsp', TRUE);
         } else {
             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), $required);
         }
     } elseif ($fieldName == 'scholarship_type_id') {
         $form->add('select', $name, $title, array('' => '-- Select -- ') + array_flip(CRM_Core_OptionGroup::values('scholarship_type', TRUE)));
     } elseif ($fieldName == 'applicant_status_id') {
         $form->add('select', $name, $title, array('' => '-- Select -- ') + array_flip(CRM_Core_OptionGroup::values('applicant_status', TRUE)));
     } elseif ($fieldName == 'highschool_gpa_id') {
         $form->add('select', $name, $title, array('' => '-- Select -- ') + CRM_Core_OptionGroup::values('highschool_gpa'));
     } elseif ($fieldName == 'world_region') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::worldRegion(), $required);
     } elseif ($fieldName == 'signature_html') {
         $form->addWysiwyg($name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName));
     } elseif ($fieldName == 'signature_text') {
         $form->add('textarea', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName));
     } elseif (substr($fieldName, -11) == 'campaign_id') {
         if (CRM_Campaign_BAO_Campaign::isCampaignEnable()) {
             $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(CRM_Utils_Array::value($contactId, $form->_componentCampaigns));
             $campaign =& $form->add('select', $name, $title, array('' => ts('- select -')) + $campaigns, $required, 'class="big"');
         }
     } elseif ($fieldName == 'activity_details') {
         $form->addWysiwyg($fieldName, $title, array('rows' => 4, 'cols' => 60), $required);
     } elseif ($fieldName == 'activity_duration') {
         $form->add('text', $fieldName, $title, $attributes, $required);
         $form->addRule($name, ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger');
     } else {
         $processed = FALSE;
         if (CRM_Core_Permission::access('Quest', FALSE)) {
             $processed = CRM_Quest_BAO_Student::buildStudentForm($form, $fieldName, $title, $contactId);
         }
         if (!$processed) {
             if (substr($fieldName, 0, 3) === 'is_' or substr($fieldName, 0, 7) === 'do_not_') {
                 $form->add('advcheckbox', $name, $title, $attributes, $required);
             } else {
                 $form->add('text', $name, $title, $attributes, $required);
             }
         }
     }
     static $hiddenSubtype = FALSE;
     if (!$hiddenSubtype && CRM_Contact_BAO_ContactType::isaSubType($field['field_type'])) {
         // In registration mode params are submitted via POST and we don't have any clue
         // about profile-id or the profile-type (which could be a subtype)
         // To generalize the  behavior and simplify the process,
         // lets always add the hidden
         //subtype value if there is any, and we won't have to
         // compute it while processing.
         if ($onBehalf) {
             $form->addElement('hidden', 'onbehalf[contact_sub_type]', $field['field_type']);
         } else {
             $form->addElement('hidden', 'contact_sub_type_hidden', $field['field_type']);
         }
         $hiddenSubtype = TRUE;
     }
     if ($view && $mode != CRM_Profile_Form::MODE_SEARCH || $isShared) {
         $form->freeze($name);
     }
     //add the rules
     if (in_array($fieldName, array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) {
         $form->addRule($name, ts('Please enter a valid amount.'), 'money');
     }
     if ($rule) {
         if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) {
             $form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule);
         }
     }
 }
 private function diffsInTable($table)
 {
     // caches for pretty field titles and value mappings
     static $titles = null;
     static $values = null;
     $params = array(1 => array($this->log_conn_id, 'Integer'), 2 => array($this->log_date, 'String'));
     // we look for the last change in the given connection that happended less than 10 seconds later than log_date to catch multi-query changes
     $changedSQL = "SELECT * FROM `{$this->loggingDB}`.`{$table}` WHERE log_conn_id = %1 AND log_date < DATE_ADD(%2, INTERVAL 10 SECOND) ORDER BY log_date DESC LIMIT 1";
     $changed = $this->sqlToArray($changedSQL, $params);
     // return early if nothing found
     if (empty($changed)) {
         return array();
     }
     // seed caches with civicrm_contact titles/values
     if (!isset($titles['log_civicrm_contact']) or !isset($values['log_civicrm_contact'])) {
         $titles['log_civicrm_contact'] = array('gender_id' => ts('Gender'), 'preferred_communication_method' => ts('Preferred Communication Method'), 'preferred_language' => ts('Preferred Language'), 'prefix_id' => ts('Prefix'), 'suffix_id' => ts('Suffix'));
         $values['log_civicrm_contact'] = array('gender_id' => CRM_Core_PseudoConstant::gender(), 'preferred_communication_method' => CRM_Core_PseudoConstant::pcm(), 'preferred_language' => CRM_Core_PseudoConstant::languages(), 'prefix_id' => CRM_Core_PseudoConstant::individualPrefix(), 'suffix_id' => CRM_Core_PseudoConstant::individualSuffix());
         require_once 'CRM/Contact/DAO/Contact.php';
         $dao = new CRM_Contact_DAO_Contact();
         foreach ($dao->fields() as $field) {
             if (!isset($titles['log_civicrm_contact'][$field['name']])) {
                 $titles['log_civicrm_contact'][$field['name']] = $field['title'];
             }
             if ($field['type'] == CRM_Utils_Type::T_BOOLEAN) {
                 $values['log_civicrm_contact'][$field['name']] = array('0' => ts('false'), '1' => ts('true'));
             }
         }
     }
     // add custom data titles/values for the given table
     if (!isset($titles[$table]) or !isset($values[$table])) {
         $titles[$table] = array();
         $values[$table] = array();
         $params[3] = array(substr($table, 4), 'String');
         $sql = "SELECT id, title FROM `{$this->loggingDB}`.log_civicrm_custom_group WHERE log_date <= %2 AND table_name = %3 ORDER BY log_date DESC LIMIT 1";
         $cgDao =& CRM_Core_DAO::executeQuery($sql, $params);
         $cgDao->fetch();
         $params[3] = array($cgDao->id, 'Integer');
         $sql = "SELECT column_name, data_type, label, name FROM `{$this->loggingDB}`.log_civicrm_custom_field WHERE log_date <= %2 AND custom_group_id = %3 ORDER BY log_date";
         $cfDao =& CRM_Core_DAO::executeQuery($sql, $params);
         while ($cfDao->fetch()) {
             $titles[$table][$cfDao->column_name] = "{$cgDao->title}: {$cfDao->label}";
             switch ($cfDao->data_type) {
                 case 'Boolean':
                     $values[$table][$cfDao->column_name] = array('0' => ts('false'), '1' => ts('true'));
                     break;
                 case 'String':
                     $values[$table][$cfDao->column_name] = array();
                     $params[3] = array("custom_{$cfDao->name}", 'String');
                     $sql = "SELECT id FROM `{$this->loggingDB}`.log_civicrm_option_group WHERE log_date <= %2 AND name = %3 ORDER BY log_date DESC LIMIT 1";
                     $ogId = CRM_Core_DAO::singleValueQuery($sql, $params);
                     $params[3] = array($ogId, 'Integer');
                     $sql = "SELECT label, value FROM `{$this->loggingDB}`.log_civicrm_option_value WHERE log_date <= %2 AND option_group_id = %3 ORDER BY log_date";
                     $ovDao =& CRM_Core_DAO::executeQuery($sql, $params);
                     while ($ovDao->fetch()) {
                         $values[$table][$cfDao->column_name][$ovDao->value] = $ovDao->label;
                     }
                     break;
             }
         }
     }
     // we look for the previous state (different log_conn_id) of the found id
     $params[3] = array($changed['id'], 'Integer');
     $originalSQL = "SELECT * FROM `{$this->loggingDB}`.`{$table}` WHERE log_conn_id != %1 AND log_date < %2 AND id = %3 ORDER BY log_date DESC LIMIT 1";
     $original = $this->sqlToArray($originalSQL, $params);
     $rows = array();
     // populate $rows with only the differences between $changed and $original (skipping certain columns and NULL ↔ empty changes)
     $skipped = array('entity_id', 'id', 'log_action', 'log_conn_id', 'log_date', 'log_user_id');
     foreach (array_keys(array_diff_assoc($changed, $original)) as $diff) {
         if (in_array($diff, $skipped)) {
             continue;
         }
         if ($original[$diff] == $changed[$diff]) {
             continue;
         }
         $rows[] = array('field' => isset($titles[$table][$diff]) ? $titles[$table][$diff] : substr($table, 4) . ".{$diff}", 'from' => isset($values[$table][$diff][$original[$diff]]) ? $values[$table][$diff][$original[$diff]] : $original[$diff], 'to' => isset($values[$table][$diff][$changed[$diff]]) ? $values[$table][$diff][$changed[$diff]] : $changed[$diff]);
     }
     return $rows;
 }
 /**
  * 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 None
  */
 function setDefaultValues(&$form, &$defaults)
 {
     if (!empty($defaults['preferred_language'])) {
         $languages = array_flip(CRM_Core_PseudoConstant::languages());
         $defaults['preferred_language'] = $languages[$defaults['preferred_language']];
     }
     // CRM-7119: set preferred_language to default if unset
     if (!isset($defaults['preferred_language']) or empty($defaults['preferred_language'])) {
         $config =& CRM_Core_Config::singleton();
         $defaults['preferred_language'] = $config->lcMessages;
     }
     //set default from greeting types CRM-4575.
     $greetingTypes = array('addressee' => 'addressee_id', 'email_greeting' => 'email_greeting_id', 'postal_greeting' => 'postal_greeting_id');
     if ($form->_action & CRM_Core_Action::ADD) {
         $contactTypeFilters = array(1 => 'Individual', 2 => 'Household', 3 => 'Organization');
         $filter = CRM_Utils_Array::key($form->_contactType, $contactTypeFilters);
         require_once 'CRM/Core/OptionGroup.php';
         foreach ($greetingTypes as $greetingType => $greeting) {
             if (!CRM_Utils_Array::value($greeting, $defaults)) {
                 //get the default from email address.
                 $defaultGreetingTypeId = CRM_Core_OptionGroup::values($greetingType, null, null, null, " AND is_default = 1 AND ( filter = {$filter} OR filter = 0 )", 'value');
                 if (!empty($defaultGreetingTypeId)) {
                     $defaults[$greeting] = key($defaultGreetingTypeId);
                 }
             }
         }
     } else {
         foreach ($greetingTypes as $greetingType => $greeting) {
             $name = "{$greetingType}_display";
             $form->assign($name, CRM_Utils_Array::value($name, $defaults));
         }
     }
 }
 static function basic(&$form)
 {
     $form->addElement('hidden', 'hidden_basic', 1);
     if ($form->_searchOptions['contactType']) {
         // add checkboxes for contact type
         $contact_type = array();
         $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements();
         if ($contactTypes) {
             $form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, FALSE, array('id' => 'contact_type', 'multiple' => 'multiple', 'title' => ts('- select -')));
         }
     }
     if ($form->_searchOptions['groups']) {
         // multiselect for groups
         if ($form->_group) {
             $form->add('select', 'group', ts('Groups'), $form->_group, FALSE, array('id' => 'group', 'multiple' => 'multiple', 'title' => ts('- select -')));
         }
     }
     if ($form->_searchOptions['tags']) {
         // multiselect for categories
         $contactTags = CRM_Core_BAO_Tag::getTags();
         if ($contactTags) {
             $form->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE, array('id' => 'contact_tags', 'multiple' => 'multiple', 'title' => ts('- select -')));
         }
         $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
         CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', NULL, TRUE, FALSE, TRUE);
     }
     // add text box for last name, first name, street name, city
     $form->addElement('text', 'sort_name', ts('Find...'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
     // add text box for last name, first name, street name, city
     $form->add('text', 'email', ts('Contact Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
     //added contact source
     $form->add('text', 'contact_source', ts('Contact Source'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'source'));
     //added job title
     $attributes['job_title']['size'] = 30;
     $form->addElement('text', 'job_title', ts('Job Title'), $attributes['job_title'], 'size="30"');
     //added internal ID
     $attributes['id']['size'] = 30;
     $form->addElement('text', 'id', ts('Contact ID'), $attributes['id'], 'size="30"');
     //added external ID
     $attributes['external_identifier']['size'] = 30;
     $form->addElement('text', 'external_identifier', ts('External ID'), $attributes['external_identifier'], 'size="30"');
     $config = CRM_Core_Config::singleton();
     if (CRM_Core_Permission::check('access deleted contacts') and $config->contactUndelete) {
         $form->add('checkbox', 'deleted_contacts', ts('Search in Trash') . '<br />' . ts('(deleted contacts)'));
     }
     // add checkbox for cms users only
     $form->addYesNo('uf_user', ts('CMS User?'));
     // tag all search
     $form->add('text', 'tag_search', ts('All Tags'));
     // add search profiles
     // FIXME: This is probably a part of profiles - need to be
     // FIXME: eradicated from here when profiles are reworked.
     $types = array('Participant', 'Contribution', 'Membership');
     // get component profiles
     $componentProfiles = array();
     $componentProfiles = CRM_Core_BAO_UFGroup::getProfiles($types);
     $ufGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('Search Profile', 1);
     $accessibleUfGroups = CRM_Core_Permission::ufGroup(CRM_Core_Permission::VIEW);
     $searchProfiles = array();
     foreach ($ufGroups as $key => $var) {
         if (!array_key_exists($key, $componentProfiles) && in_array($key, $accessibleUfGroups)) {
             $searchProfiles[$key] = $var['title'];
         }
     }
     $form->addElement('select', 'uf_group_id', ts('Search Views'), array('0' => ts('- default view -')) + $searchProfiles);
     $componentModes = CRM_Contact_Form_Search::getModeSelect();
     // unset contributions or participants if user does not have
     // permission on them
     if (!CRM_Core_Permission::access('CiviContribute')) {
         unset($componentModes['2']);
     }
     if (!CRM_Core_Permission::access('CiviEvent')) {
         unset($componentModes['3']);
     }
     if (!CRM_Core_Permission::access('CiviMember')) {
         unset($componentModes['5']);
     }
     if (!CRM_Core_Permission::check('view all activities')) {
         unset($componentModes['4']);
     }
     if (count($componentModes) > 1) {
         $form->addElement('select', 'component_mode', ts('Display Results As'), $componentModes);
     }
     $form->addElement('select', 'operator', ts('Search Operator'), array('AND' => ts('AND'), 'OR' => ts('OR')));
     // add the option to display relationships
     $rTypes = CRM_Core_PseudoConstant::relationshipType();
     $rSelect = array('' => ts('- Select Relationship Type-'));
     foreach ($rTypes as $rid => $rValue) {
         if ($rValue['label_a_b'] == $rValue['label_b_a']) {
             $rSelect[$rid] = $rValue['label_a_b'];
         } else {
             $rSelect["{$rid}_a_b"] = $rValue['label_a_b'];
             $rSelect["{$rid}_b_a"] = $rValue['label_b_a'];
         }
     }
     $form->addElement('select', 'display_relationship_type', ts('Display Results as Relationship'), $rSelect);
     // checkboxes for DO NOT phone, email, mail
     // we take labels from SelectValues
     $t = CRM_Core_SelectValues::privacy();
     $form->add('select', 'privacy_options', ts('Privacy'), $t, FALSE, array('id' => 'privacy_options', 'multiple' => 'multiple', 'title' => ts('- select -')));
     $form->addElement('select', 'privacy_operator', ts('Operator'), array('OR' => ts('OR'), 'AND' => ts('AND')));
     $toggleChoice = array();
     $toggleChoice[] = $form->createElement('radio', NULL, '', ' ' . ts('Exclude'), '1');
     $toggleChoice[] = $form->createElement('radio', NULL, '', ' ' . ts('Include by Privacy Option(s)'), '2');
     $form->addGroup($toggleChoice, 'privacy_toggle', 'Privacy Options');
     // preferred communication method
     $comm = CRM_Core_PseudoConstant::pcm();
     $commPreff = array();
     foreach ($comm as $k => $v) {
         $commPreff[] = $form->createElement('advcheckbox', $k, NULL, $v);
     }
     $onHold[] = $form->createElement('advcheckbox', 'on_hold', NULL, ts(''));
     $form->addGroup($onHold, 'email_on_hold', ts('Email On Hold'));
     $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Communication Method'));
     //CRM-6138 Preferred Language
     $langPreff = CRM_Core_PseudoConstant::languages();
     $form->add('select', 'preferred_language', ts('Preferred Language'), array('' => ts('- select language -')) + $langPreff);
 }
 /**
  * returns all the rows in the given offset and rowCount
  *
  * @param enum   $action   the action being performed
  * @param int    $offset   the row number to start from
  * @param int    $rowCount the number of rows to return
  * @param string $sort     the sql string that describes the sort order
  * @param enum   $output   what should the result set include (web/email/csv)
  *
  * @return int   the total number of rows for this action
  */
 function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
 {
     $multipleFields = array('url');
     //$sort object processing for location fields
     if ($sort) {
         $vars = $sort->_vars;
         $varArray = array();
         foreach ($vars as $key => $field) {
             $field = $vars[$key];
             $fieldArray = explode('-', $field['name']);
             $fieldType = CRM_Utils_Array::value('2', $fieldArray);
             if (is_numeric(CRM_Utils_Array::value('1', $fieldArray))) {
                 if (!in_array($fieldType, $multipleFields)) {
                     $locationType = new CRM_Core_DAO_LocationType();
                     $locationType->id = $fieldArray[1];
                     $locationType->find(TRUE);
                     if ($fieldArray[0] == 'email' || $fieldArray[0] == 'im' || $fieldArray[0] == 'phone') {
                         $field['name'] = "`" . $locationType->name . "-" . $fieldArray[0] . "-1`";
                     } else {
                         $field['name'] = "`" . $locationType->name . "-" . $fieldArray[0] . "`";
                     }
                 } else {
                     $field['name'] = "`website-" . $fieldArray[1] . "-{$fieldType}`";
                 }
             }
             $varArray[$key] = $field;
         }
     }
     $sort->_vars = $varArray;
     $additionalWhereClause = 'contact_a.is_deleted = 0';
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, NULL, NULL, NULL, NULL, NULL, $additionalWhereClause);
     // process the result of the query
     $rows = array();
     // check if edit is configured in profile settings
     if ($this->_gid) {
         $editLink = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'is_edit_link');
     }
     //FIXME : make sure to handle delete separately. CRM-4418
     $mask = CRM_Core_Action::mask(array(CRM_Core_Permission::getPermission()));
     if ($editLink && $mask & CRM_Core_Permission::EDIT) {
         // do not allow edit for anon users in joomla frontend, CRM-4668
         $config = CRM_Core_Config::singleton();
         if (!$config->userFrameworkFrontend) {
             $this->_editLink = TRUE;
         }
     }
     $links = self::links($this->_map, $this->_editLink, $this->_linkToUF, $this->_profileIds);
     $locationTypes = CRM_Core_PseudoConstant::locationType();
     $names = array();
     static $skipFields = array('group', 'tag');
     foreach ($this->_fields as $key => $field) {
         if (CRM_Utils_Array::value('in_selector', $field) && !in_array($key, $skipFields)) {
             if (strpos($key, '-') !== FALSE) {
                 $value = explode('-', $key);
                 $fieldName = CRM_Utils_Array::value(0, $value);
                 $id = CRM_Utils_Array::value(1, $value);
                 $type = CRM_Utils_Array::value(2, $value);
                 if (!in_array($fieldName, $multipleFields)) {
                     $locationTypeName = NULL;
                     if (is_numeric($id)) {
                         $locationTypeName = CRM_Utils_Array::value($id, $locationTypes);
                     } else {
                         if ($id == 'Primary') {
                             $locationTypeName = 1;
                         }
                     }
                     if (!$locationTypeName) {
                         continue;
                     }
                     $locationTypeName = str_replace(' ', '_', $locationTypeName);
                     if (in_array($fieldName, array('phone', 'im', 'email'))) {
                         if ($type) {
                             $names[] = "{$locationTypeName}-{$fieldName}-{$type}";
                         } else {
                             $names[] = "{$locationTypeName}-{$fieldName}";
                         }
                     } else {
                         $names[] = "{$locationTypeName}-{$fieldName}";
                     }
                 } else {
                     $names[] = "website-{$id}-{$fieldName}";
                 }
             } elseif ($field['name'] == 'id') {
                 $names[] = 'contact_id';
             } else {
                 $names[] = $field['name'];
             }
         }
     }
     $multipleSelectFields = array('preferred_communication_method' => 1);
     if (CRM_Core_Permission::access('Quest')) {
         $multipleSelectFields = CRM_Quest_BAO_Student::$multipleSelectFields;
     }
     // we need to determine of overlay profile should be shown
     $showProfileOverlay = CRM_Core_BAO_UFGroup::showOverlayProfile();
     $imProviders = CRM_Core_PseudoConstant::IMProvider();
     $websiteTypes = CRM_Core_PseudoConstant::websiteType();
     $languages = CRM_Core_PseudoConstant::languages();
     while ($result->fetch()) {
         if (isset($result->country)) {
             // the query returns the untranslated country name
             $i18n = CRM_Core_I18n::singleton();
             $result->country = $i18n->translate($result->country);
         }
         $row = array();
         $empty = TRUE;
         $row[] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id, $showProfileOverlay);
         if ($result->sort_name) {
             $row['sort_name'] = $result->sort_name;
             $empty = FALSE;
         } else {
             continue;
         }
         foreach ($names as $name) {
             if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 $row[] = CRM_Core_BAO_CustomField::getDisplayValue($result->{$name}, $cfID, $this->_options, $result->contact_id);
             } elseif (substr($name, -4) == '-url' && !empty($result->{$name})) {
                 $url = CRM_Utils_System::fixURL($result->{$name});
                 $typeId = substr($name, 0, -4) . "-website_type_id";
                 $typeName = $websiteTypes[$result->{$typeId}];
                 if ($typeName) {
                     $row[] = "<a href=\"{$url}\">{$result->{$name}} ({$typeName})</a>";
                 } else {
                     $row[] = "<a href=\"{$url}\">{$result->{$name}}</a>";
                 }
             } elseif ($name == 'preferred_language') {
                 $row[] = $languages[$result->{$name}];
             } elseif ($multipleSelectFields && array_key_exists($name, $multipleSelectFields)) {
                 //fix to display student checkboxes
                 $key = $name;
                 $paramsNew = array($key => $result->{$name});
                 if ($key == 'test_tutoring') {
                     $name = array($key => array('newName' => $key, 'groupName' => 'test'));
                     // for  readers group
                 } elseif (substr($key, 0, 4) == 'cmr_') {
                     $name = array($key => array('newName' => $key, 'groupName' => substr($key, 0, -3)));
                 } else {
                     $name = array($key => array('newName' => $key, 'groupName' => $key));
                 }
                 CRM_Core_OptionGroup::lookupValues($paramsNew, $name, FALSE);
                 $row[] = $paramsNew[$key];
             } elseif (strpos($name, '-im')) {
                 if (!empty($result->{$name})) {
                     $providerId = $name . "-provider_id";
                     $providerName = $imProviders[$result->{$providerId}];
                     $row[] = $result->{$name} . " ({$providerName})";
                 } else {
                     $row[] = '';
                 }
             } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting'))) {
                 $dname = $name . '_display';
                 $row[] = $result->{$dname};
             } elseif (in_array($name, array('birth_date', 'deceased_date'))) {
                 $row[] = CRM_Utils_Date::customFormat($result->{$name});
             } elseif (isset($result->{$name})) {
                 $row[] = $result->{$name};
             } else {
                 $row[] = '';
             }
             if (!empty($result->{$name})) {
                 $empty = FALSE;
             }
         }
         $newLinks = $links;
         $params = array('id' => $result->contact_id, 'gid' => implode(',', $this->_profileIds));
         if ($this->_linkToUF) {
             $ufID = CRM_Core_BAO_UFMatch::getUFId($result->contact_id);
             if (!$ufID) {
                 unset($newLinks[CRM_Core_Action::PROFILE]);
             } else {
                 $params['ufID'] = $ufID;
             }
         }
         $row[] = CRM_Core_Action::formLink($newLinks, $mask, $params);
         if (!$empty) {
             $rows[] = $row;
         }
     }
     return $rows;
 }
示例#8
0
 /**
  * Given the list of params in the params array, fetch the object
  * and store the values in the values array
  *
  * @param array $params input parameters to find object
  * @param array $values output values of the object
  *
  * @return CRM_Contact_BAO_Contact|null the found object or null
  * @access public
  * @static
  */
 private static function _getValues(&$params, &$values)
 {
     $contact = new CRM_Contact_BAO_Contact();
     $contact->copyValues($params);
     if ($contact->find(true)) {
         CRM_Core_DAO::storeValues($contact, $values);
         $privacy = array();
         foreach (self::$_commPrefs as $name) {
             if (isset($contact->{$name})) {
                 $privacy[$name] = $contact->{$name};
             }
         }
         if (!empty($privacy)) {
             $values['privacy'] = $privacy;
         }
         // communication Prefferance
         $preffComm = $comm = array();
         $comm = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $contact->preferred_communication_method);
         foreach ($comm as $value) {
             $preffComm[$value] = 1;
         }
         $temp = array('preferred_communication_method' => $contact->preferred_communication_method);
         $names = array('preferred_communication_method' => array('newName' => 'preferred_communication_method_display', 'groupName' => 'preferred_communication_method'));
         require_once 'CRM/Core/OptionGroup.php';
         CRM_Core_OptionGroup::lookupValues($temp, $names, false);
         $values['preferred_communication_method'] = $preffComm;
         $values['preferred_communication_method_display'] = CRM_Utils_Array::value('preferred_communication_method_display', $temp);
         CRM_Contact_DAO_Contact::addDisplayEnums($values);
         // get preferred languages
         if (!empty($contact->preferred_language)) {
             $languages =& CRM_Core_PseudoConstant::languages();
             $values['preferred_language'] = CRM_Utils_Array::value($contact->preferred_language, $languages);
         }
         // Calculating Year difference
         if ($contact->birth_date) {
             $birthDate = CRM_Utils_Date::customFormat($contact->birth_date, '%Y%m%d');
             if ($birthDate < date('Ymd')) {
                 $age = CRM_Utils_Date::calculateAge($birthDate);
                 $values['age']['y'] = CRM_Utils_Array::value('years', $age);
                 $values['age']['m'] = CRM_Utils_Array::value('months', $age);
             }
             list($values['birth_date']) = CRM_Utils_Date::setDateDefaults($contact->birth_date, 'birth');
             $values['birth_date_display'] = $contact->birth_date;
         }
         if ($contact->deceased_date) {
             list($values['deceased_date']) = CRM_Utils_Date::setDateDefaults($contact->deceased_date, 'birth');
             $values['deceased_date_display'] = $contact->deceased_date;
         }
         $contact->contact_id = $contact->id;
         return $contact;
     }
     return null;
 }
 function titlesAndValuesForTable($table)
 {
     // static caches for subsequent calls with the same $table
     static $titles = array();
     static $values = array();
     // FIXME: split off the table → DAO mapping to a GenCode-generated class
     static $daos = array('civicrm_address' => 'CRM_Core_DAO_Address', 'civicrm_contact' => 'CRM_Contact_DAO_Contact', 'civicrm_email' => 'CRM_Core_DAO_Email', 'civicrm_im' => 'CRM_Core_DAO_IM', 'civicrm_openid' => 'CRM_Core_DAO_OpenID', 'civicrm_phone' => 'CRM_Core_DAO_Phone', 'civicrm_website' => 'CRM_Core_DAO_Website', 'civicrm_contribution' => 'CRM_Contribute_DAO_Contribution', 'civicrm_note' => 'CRM_Core_DAO_Note', 'civicrm_relationship' => 'CRM_Contact_DAO_Relationship');
     if (!isset($titles[$table]) or !isset($values[$table])) {
         if (in_array($table, array_keys($daos))) {
             // FIXME: these should be populated with pseudo constants as they
             // were at the time of logging rather than their current values
             $values[$table] = array('contribution_page_id' => CRM_Contribute_PseudoConstant::contributionPage(), 'contribution_status_id' => CRM_Contribute_PseudoConstant::contributionStatus(), 'contribution_type_id' => CRM_Contribute_PseudoConstant::contributionType(), 'country_id' => CRM_Core_PseudoConstant::country(), 'gender_id' => CRM_Core_PseudoConstant::gender(), 'location_type_id' => CRM_Core_PseudoConstant::locationType(), 'payment_instrument_id' => CRM_Contribute_PseudoConstant::paymentInstrument(), 'phone_type_id' => CRM_Core_PseudoConstant::phoneType(), 'preferred_communication_method' => CRM_Core_PseudoConstant::pcm(), 'preferred_language' => CRM_Core_PseudoConstant::languages(), 'prefix_id' => CRM_Core_PseudoConstant::individualPrefix(), 'provider_id' => CRM_Core_PseudoConstant::IMProvider(), 'state_province_id' => CRM_Core_PseudoConstant::stateProvince(), 'suffix_id' => CRM_Core_PseudoConstant::individualSuffix(), 'website_type_id' => CRM_Core_PseudoConstant::websiteType());
             require_once str_replace('_', DIRECTORY_SEPARATOR, $daos[$table]) . '.php';
             eval("\$dao = new {$daos[$table]};");
             foreach ($dao->fields() as $field) {
                 $titles[$table][$field['name']] = CRM_Utils_Array::value('title', $field);
                 if ($field['type'] == CRM_Utils_Type::T_BOOLEAN) {
                     $values[$table][$field['name']] = array('0' => ts('false'), '1' => ts('true'));
                 }
             }
         } elseif (substr($table, 0, 14) == 'civicrm_value_') {
             list($titles[$table], $values[$table]) = $this->titlesAndValuesForCustomDataTable($table);
         }
     }
     return array($titles[$table], $values[$table]);
 }
示例#10
0
 /**
  * Function to build profile form
  *
  * @params object  $form       form object
  * @params array   $field      array field properties
  * @params int     $mode       profile mode
  * @params int     $contactID  contact id
  *
  * @return null
  * @static
  * @access public
  */
 static function buildProfile(&$form, &$field, $mode, $contactId = null, $online = false)
 {
     require_once "CRM/Profile/Form.php";
     require_once "CRM/Core/OptionGroup.php";
     require_once 'CRM/Core/BAO/UFField.php';
     require_once 'CRM/Contact/BAO/ContactType.php';
     $defaultValues = array();
     $fieldName = $field['name'];
     $title = $field['title'];
     $attributes = $field['attributes'];
     $rule = $field['rule'];
     $view = $field['is_view'];
     $required = $mode == CRM_Profile_Form::MODE_SEARCH ? false : $field['is_required'];
     $search = $mode == CRM_Profile_Form::MODE_SEARCH ? true : false;
     // do not display view fields in drupal registration form
     // CRM-4632
     if ($view && $mode == CRM_Profile_Form::MODE_REGISTER) {
         return;
     }
     if ($contactId && !$online) {
         $name = "field[{$contactId}][{$fieldName}]";
     } else {
         $name = $fieldName;
     }
     if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) {
         $deleteExtra = ts('Are you sure you want to delete contact image.');
         $deleteURL = array(CRM_Core_Action::DELETE => array('name' => ts('Delete Contact Image'), 'url' => 'civicrm/contact/image', 'qs' => 'reset=1&id=%%id%%&gid=%%gid%%&action=delete', 'extra' => 'onclick = "if (confirm( \'' . $deleteExtra . '\' ) ) this.href+=\'&amp;confirmed=1\'; else return false;"'));
         $deleteURL = CRM_Core_Action::formLink($deleteURL, CRM_Core_Action::DELETE, array('id' => $form->get('id'), 'gid' => $form->get('gid')));
         $form->assign('deleteURL', $deleteURL);
     }
     require_once 'CRM/Core/BAO/Preferences.php';
     $addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true);
     if (substr($fieldName, 0, 14) === 'state_province') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required);
     } else {
         if (substr($fieldName, 0, 7) === 'country') {
             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required);
             $config = CRM_Core_Config::singleton();
             if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactCountry) {
                 $defaultValues[$name] = $config->defaultContactCountry;
                 $form->setDefaults($defaultValues);
             }
         } else {
             if (substr($fieldName, 0, 6) === 'county') {
                 if ($addressOptions['county']) {
                     $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::county(), $required);
                 }
             } else {
                 if (substr($fieldName, 0, 9) === 'image_URL') {
                     $form->add('file', $name, $title, $attributes, $required);
                     $form->addUploadElement($name);
                 } else {
                     if (substr($fieldName, 0, 2) === 'im') {
                         if (!$contactId) {
                             $form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::IMProvider(), $required);
                             if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) {
                                 $form->freeze($name . "-provider_id");
                             }
                         }
                         $form->add('text', $name, $title, $attributes, $required);
                     } else {
                         if ($fieldName === 'birth_date' || $fieldName === 'deceased_date') {
                             $form->addDate($name, $title, $required, array('formatType' => 'birth'));
                         } else {
                             if (in_array($fieldName, array("membership_start_date", "membership_end_date", "join_date"))) {
                                 $form->addDate($name, $title, $required, array('formatType' => 'custom'));
                             } else {
                                 if ($field['name'] == 'membership_type_id') {
                                     require_once 'CRM/Member/PseudoConstant.php';
                                     $form->add('select', 'membership_type_id', $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipType(), $required);
                                 } else {
                                     if ($field['name'] == 'status_id' && ($mode && CRM_Contact_BAO_Query::MODE_MEMBER)) {
                                         require_once 'CRM/Member/PseudoConstant.php';
                                         $form->add('select', 'status_id', $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(null, null, 'label'), $required);
                                     } else {
                                         if ($fieldName === 'gender') {
                                             $genderOptions = array();
                                             $gender = CRM_Core_PseudoConstant::gender();
                                             foreach ($gender as $key => $var) {
                                                 $genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key);
                                             }
                                             $form->addGroup($genderOptions, $name, $title);
                                             if ($required) {
                                                 $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required');
                                             }
                                         } else {
                                             if ($fieldName === 'individual_prefix') {
                                                 $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required);
                                             } else {
                                                 if ($fieldName === 'individual_suffix') {
                                                     $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required);
                                                 } else {
                                                     if ($fieldName === 'contact_sub_type') {
                                                         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $form->_fields[$fieldName]);
                                                         $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : null;
                                                         $setSubtype = false;
                                                         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
                                                             $setSubtype = $profileType;
                                                             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
                                                         }
                                                         $subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array();
                                                         if ($setSubtype) {
                                                             $subtypeList = array();
                                                             $subtypeList[$setSubtype] = $subtypes[$setSubtype];
                                                         } else {
                                                             $subtypeList = array('' => ts('- select -')) + $subtypes;
                                                         }
                                                         $form->add('select', $name, $title, $subtypeList, $required);
                                                     } else {
                                                         if (in_array($fieldName, array('email_greeting', 'postal_greeting', 'addressee'))) {
                                                             //add email greeting, postal greeting, addressee, CRM-4575
                                                             $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
                                                             $profileType = CRM_Core_BAO_UFField::getProfileType($gId, true, false, true);
                                                             if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) {
                                                                 $profileType = 'Individual';
                                                             }
                                                             if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
                                                                 $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
                                                             }
                                                             if ($fieldName == 'email_greeting') {
                                                                 $emailGreeting = array('contact_type' => $profileType, 'greeting_type' => 'email_greeting');
                                                                 $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($emailGreeting), $required);
                                                                 // adding custom email greeting element alongwith email greeting
                                                                 $form->add('text', 'email_greeting_custom', ts('Custom Email Greeting'), null, false);
                                                             } else {
                                                                 if ($fieldName === 'postal_greeting') {
                                                                     $postalGreeting = array('contact_type' => $profileType, 'greeting_type' => 'postal_greeting');
                                                                     $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($postalGreeting), $required);
                                                                     // adding custom postal greeting element alongwith postal greeting
                                                                     $form->add('text', 'postal_greeting_custom', ts('Custom Postal Greeting'), null, false);
                                                                 } else {
                                                                     if ($fieldName === 'addressee') {
                                                                         $addressee = array('contact_type' => $profileType, 'greeting_type' => 'addressee');
                                                                         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($addressee), $required);
                                                                         // adding custom addressee  element alongwith addressee type
                                                                         $form->add('text', 'addressee_custom', ts('Custom Addressee'), null, false);
                                                                     }
                                                                 }
                                                             }
                                                         } else {
                                                             if ($fieldName === 'preferred_communication_method') {
                                                                 $communicationFields = CRM_Core_PseudoConstant::pcm();
                                                                 foreach ($communicationFields as $key => $var) {
                                                                     if ($key == '') {
                                                                         continue;
                                                                     }
                                                                     $communicationOptions[] =& HTML_QuickForm::createElement('checkbox', $key, null, $var);
                                                                 }
                                                                 $form->addGroup($communicationOptions, $name, $title, '<br/>');
                                                             } else {
                                                                 if ($fieldName === 'preferred_mail_format') {
                                                                     $form->add('select', $name, $title, CRM_Core_SelectValues::pmf());
                                                                 } else {
                                                                     if ($fieldName === 'preferred_language') {
                                                                         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::languages());
                                                                     } else {
                                                                         if ($fieldName == 'external_identifier') {
                                                                             $form->add('text', $name, $title, $attributes, $required);
                                                                             $contID = $contactId;
                                                                             if (!$contID) {
                                                                                 $contID = $form->get('id');
                                                                             }
                                                                             $form->addRule($name, ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $contID, 'external_identifier'));
                                                                         } else {
                                                                             if ($fieldName === 'group') {
                                                                                 require_once 'CRM/Contact/Form/Edit/TagsAndGroups.php';
                                                                                 CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, true, $required, $title, null, $name);
                                                                             } else {
                                                                                 if ($fieldName === 'tag') {
                                                                                     require_once 'CRM/Contact/Form/Edit/TagsAndGroups.php';
                                                                                     CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::TAG, false, $required, null, $title, $name);
                                                                                 } else {
                                                                                     if (substr($fieldName, 0, 4) === 'url-') {
                                                                                         $form->addElement('text', $name, $title, array_merge(CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), array('onfocus' => "if (!this.value) this.value='http://'; else return false", 'onblur' => "if ( this.value == 'http://') this.value=''; else return false")));
                                                                                         $form->addRule($name, ts('Enter a valid Website.'), 'url');
                                                                                         //Website type select
                                                                                         $form->addElement('select', $name . '-website_type_id', null, CRM_Core_PseudoConstant::websiteType());
                                                                                     } else {
                                                                                         if ($fieldName == 'note') {
                                                                                             //added because note appeared as a standard text input
                                                                                             $form->add('textarea', $name, $title, $attributes, $required);
                                                                                         } else {
                                                                                             if (substr($fieldName, 0, 6) === 'custom') {
                                                                                                 $customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName);
                                                                                                 if ($customFieldID) {
                                                                                                     CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, false, $required, $search, $title);
                                                                                                 }
                                                                                             } else {
                                                                                                 if (substr($fieldName, 0, 14) === 'address_custom') {
                                                                                                     list($fName, $locTypeId) = CRM_Utils_System::explode('-', $fieldName, 2);
                                                                                                     $customFieldID = CRM_Core_BAO_CustomField::getKeyID(substr($fName, 8));
                                                                                                     if ($customFieldID) {
                                                                                                         CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, false, $required, $search, $title);
                                                                                                     }
                                                                                                 } else {
                                                                                                     if (in_array($fieldName, array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) {
                                                                                                         $form->addDate($name, $title, $required, array('formatType' => 'custom'));
                                                                                                     } else {
                                                                                                         if ($fieldName == 'payment_instrument') {
                                                                                                             require_once "CRM/Contribute/PseudoConstant.php";
                                                                                                             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required);
                                                                                                         } else {
                                                                                                             if ($fieldName == 'contribution_type') {
                                                                                                                 require_once "CRM/Contribute/PseudoConstant.php";
                                                                                                                 $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType(), $required);
                                                                                                             } else {
                                                                                                                 if ($fieldName == 'contribution_status_id') {
                                                                                                                     require_once "CRM/Contribute/PseudoConstant.php";
                                                                                                                     $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionStatus(), $required);
                                                                                                                 } else {
                                                                                                                     if ($fieldName == 'participant_register_date') {
                                                                                                                         $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
                                                                                                                     } else {
                                                                                                                         if ($fieldName == 'activity_status_id') {
                                                                                                                             require_once 'CRM/Core/PseudoConstant.php';
                                                                                                                             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::activityStatus(), $required);
                                                                                                                         } else {
                                                                                                                             if ($fieldName == 'activity_date_time') {
                                                                                                                                 $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
                                                                                                                             } else {
                                                                                                                                 if ($fieldName == 'participant_status_id') {
                                                                                                                                     require_once "CRM/Event/PseudoConstant.php";
                                                                                                                                     $cond = null;
                                                                                                                                     if ($online == true) {
                                                                                                                                         $cond = "visibility_id = 1";
                                                                                                                                     }
                                                                                                                                     $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(null, $cond, 'label'), $required);
                                                                                                                                 } else {
                                                                                                                                     if ($fieldName == 'participant_role_id') {
                                                                                                                                         require_once "CRM/Event/PseudoConstant.php";
                                                                                                                                         if (CRM_Utils_Array::value('is_multiple', $field)) {
                                                                                                                                             require_once "CRM/Event/PseudoConstant.php";
                                                                                                                                             $form->addCheckBox($name, $title, CRM_Event_PseudoConstant::participantRole(), null, null, null, null, '&nbsp', true);
                                                                                                                                         } else {
                                                                                                                                             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), $required);
                                                                                                                                         }
                                                                                                                                     } else {
                                                                                                                                         if ($fieldName == 'scholarship_type_id') {
                                                                                                                                             $form->add('select', $name, $title, array("" => "-- Select -- ") + array_flip(CRM_Core_OptionGroup::values('scholarship_type', true)));
                                                                                                                                         } else {
                                                                                                                                             if ($fieldName == 'applicant_status_id') {
                                                                                                                                                 $form->add('select', $name, $title, array("" => "-- Select -- ") + array_flip(CRM_Core_OptionGroup::values('applicant_status', true)));
                                                                                                                                             } else {
                                                                                                                                                 if ($fieldName == 'highschool_gpa_id') {
                                                                                                                                                     $form->add('select', $name, $title, array("" => "-- Select -- ") + CRM_Core_OptionGroup::values('highschool_gpa'));
                                                                                                                                                 } else {
                                                                                                                                                     if ($fieldName == 'world_region') {
                                                                                                                                                         require_once "CRM/Core/PseudoConstant.php";
                                                                                                                                                         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::worldRegion(), $required);
                                                                                                                                                     } else {
                                                                                                                                                         if ($fieldName == 'signature_html') {
                                                                                                                                                             $form->addWysiwyg($name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName));
                                                                                                                                                         } else {
                                                                                                                                                             if ($fieldName == 'signature_text') {
                                                                                                                                                                 $form->add('textarea', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName));
                                                                                                                                                             } else {
                                                                                                                                                                 $processed = false;
                                                                                                                                                                 if (CRM_Core_Permission::access('Quest', false)) {
                                                                                                                                                                     require_once 'CRM/Quest/BAO/Student.php';
                                                                                                                                                                     $processed = CRM_Quest_BAO_Student::buildStudentForm($form, $fieldName, $title, $contactId);
                                                                                                                                                                 }
                                                                                                                                                                 if (!$processed) {
                                                                                                                                                                     if (substr($fieldName, 0, 3) === 'is_' or substr($fieldName, 0, 7) === 'do_not_') {
                                                                                                                                                                         $form->add('checkbox', $name, $title, $attributes, $required);
                                                                                                                                                                     } else {
                                                                                                                                                                         $form->add('text', $name, $title, $attributes, $required);
                                                                                                                                                                     }
                                                                                                                                                                 }
                                                                                                                                                             }
                                                                                                                                                         }
                                                                                                                                                     }
                                                                                                                                                 }
                                                                                                                                             }
                                                                                                                                         }
                                                                                                                                     }
                                                                                                                                 }
                                                                                                                             }
                                                                                                                         }
                                                                                                                     }
                                                                                                                 }
                                                                                                             }
                                                                                                         }
                                                                                                     }
                                                                                                 }
                                                                                             }
                                                                                         }
                                                                                     }
                                                                                 }
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     static $hiddenSubtype = false;
     if (!$hiddenSubtype && CRM_Contact_BAO_ContactType::isaSubType($field['field_type'])) {
         // In registration mode params are submitted via POST and we don't have any clue
         // about profile-id or the profile-type (which could be a subtype)
         // To generalize the  behavior and simplify the process,
         // lets always add the hidden
         //subtype value if there is any, and we won't have to
         // compute it while processing.
         $form->addElement('hidden', 'contact_sub_type_hidden', $field['field_type']);
         $hiddenSubtype = true;
     }
     if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) {
         $form->freeze($name);
     }
     //add the rules
     if (in_array($fieldName, array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) {
         $form->addRule($name, ts('Please enter a valid amount.'), 'money');
     }
     if ($rule) {
         if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) {
             $form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule);
         }
     }
 }
示例#11
0
 static function basic(&$form)
 {
     $form->addElement('hidden', 'hidden_basic', 1);
     if ($form->_searchOptions['contactType']) {
         // add checkboxes for contact type
         $contact_type = array();
         require_once 'CRM/Contact/BAO/ContactType.php';
         $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements();
         if ($contactTypes) {
             $form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, false, array('id' => 'contact_type', 'multiple' => 'multiple', 'title' => ts('- select -')));
         }
     }
     if ($form->_searchOptions['groups']) {
         // multiselect for groups
         if ($form->_group) {
             $form->add('select', 'group', ts('Groups'), $form->_group, false, array('id' => 'group', 'multiple' => 'multiple', 'title' => ts('- select -')));
         }
     }
     if ($form->_searchOptions['tags']) {
         // multiselect for categories
         require_once 'CRM/Core/BAO/Tag.php';
         $contactTags = CRM_Core_BAO_Tag::getTags();
         if ($contactTags) {
             $form->add('select', 'contact_tags', ts('Tags'), $contactTags, false, array('id' => 'contact_tags', 'multiple' => 'multiple', 'title' => ts('- select -')));
         }
         require_once 'CRM/Core/Form/Tag.php';
         require_once 'CRM/Core/BAO/Tag.php';
         $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
         CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', null, true);
     }
     // add text box for last name, first name, street name, city
     $form->addElement('text', 'sort_name', ts('Find...'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
     // add text box for last name, first name, street name, city
     $form->add('text', 'email', ts('Contact Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
     //added contact source
     $form->add('text', 'contact_source', ts('Contact Source'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'source'));
     //added job title
     $attributes['job_title']['size'] = 30;
     $form->addElement('text', 'job_title', ts('Job Title'), $attributes['job_title'], 'size="30"');
     $config =& CRM_Core_Config::singleton();
     if (CRM_Core_Permission::check('access deleted contacts') and $config->contactUndelete) {
         $form->add('checkbox', 'deleted_contacts', ts('Search in Trash (deleted contacts)'));
     }
     // add checkbox for cms users only
     $form->addYesNo('uf_user', ts('CMS User?'));
     // add search profiles
     require_once 'CRM/Core/BAO/UFGroup.php';
     // FIXME: This is probably a part of profiles - need to be
     // FIXME: eradicated from here when profiles are reworked.
     $types = array('Participant', 'Contribution', 'Membership');
     // get component profiles
     $componentProfiles = array();
     $componentProfiles = CRM_Core_BAO_UFGroup::getProfiles($types);
     $ufGroups =& CRM_Core_BAO_UFGroup::getModuleUFGroup('Search Profile', 1);
     $accessibleUfGroups = CRM_Core_Permission::ufGroup(CRM_Core_Permission::VIEW);
     $searchProfiles = array();
     foreach ($ufGroups as $key => $var) {
         if (!array_key_exists($key, $componentProfiles) && in_array($key, $accessibleUfGroups)) {
             $searchProfiles[$key] = $var['title'];
         }
     }
     $form->addElement('select', 'uf_group_id', ts('Search Views'), array('0' => ts('- default view -')) + $searchProfiles);
     require_once 'CRM/Contact/Form/Search.php';
     $componentModes =& CRM_Contact_Form_Search::getModeSelect();
     // unset contributions or participants if user does not have
     // permission on them
     if (!CRM_Core_Permission::access('CiviContribute')) {
         unset($componentModes['2']);
     }
     if (!CRM_Core_Permission::access('CiviEvent')) {
         unset($componentModes['3']);
     }
     if (!CRM_Core_Permission::check('view all activities')) {
         unset($componentModes['4']);
     }
     if (count($componentModes) > 1) {
         $form->addElement('select', 'component_mode', ts('Display Results As'), $componentModes);
     }
     // checkboxes for DO NOT phone, email, mail
     // we take labels from SelectValues
     $t = CRM_Core_SelectValues::privacy();
     $t['do_not_toggle'] = ts('Include contacts who have these privacy option(s).');
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_phone', null, $t['do_not_phone']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_email', null, $t['do_not_email']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_mail', null, $t['do_not_mail']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_sms', null, $t['do_not_sms']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_trade', null, $t['do_not_trade']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_toggle', null, $t['do_not_toggle']);
     $form->addGroup($privacy, 'privacy', ts('Privacy'), array('&nbsp;', '&nbsp;', '&nbsp;', '<br/>'));
     // preferred communication method
     require_once 'CRM/Core/PseudoConstant.php';
     $comm = CRM_Core_PseudoConstant::pcm();
     $commPreff = array();
     foreach ($comm as $k => $v) {
         $commPreff[] = HTML_QuickForm::createElement('advcheckbox', $k, null, $v);
     }
     $onHold[] = HTML_QuickForm::createElement('advcheckbox', 'on_hold', null, ts(''));
     $form->addGroup($onHold, 'email_on_hold', ts('Email On Hold'));
     $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Communication Method'));
     //CRM-6138 Preferred Language
     $langPreff = CRM_Core_PseudoConstant::languages();
     $form->add('select', 'preferred_language', ts('Preferred Language'), array('' => ts('- select language -')) + $langPreff);
 }