/** * This function provides the HTML form elements that are specific to the Individual Contact Type * * @access public * @return None */ function buildQuickForm(&$form) { $form->applyFilter('__ALL__', 'trim'); // prefix $form->addElement('select', 'prefix_id', ts('Prefix'), array('' => ts('- prefix -')) + CRM_Core_PseudoConstant::individualPrefix()); $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Individual'); // first_name $form->addElement('text', 'first_name', ts('First Name'), $attributes['first_name']); //middle_name $form->addElement('text', 'middle_name', ts('Middle Name'), $attributes['middle_name']); // last_name $form->addElement('text', 'last_name', ts('Last Name'), $attributes['last_name']); // suffix $form->addElement('select', 'suffix_id', ts('Suffix'), array('' => ts('- suffix -')) + CRM_Core_PseudoConstant::individualSuffix()); // nick_name $form->addElement('text', 'nick_name', ts('Nick Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'nick_name')); // greeting type $form->addElement('select', 'greeting_type', ts('Greeting'), CRM_Core_SelectValues::greeting()); // job title $form->addElement('text', 'job_title', ts('Job title'), $attributes['job_title']); // radio button for 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, 'gender_id', ts('Gender')); $form->addElement('checkbox', 'is_deceased', null, ts('Contact is deceased')); $form->addElement('date', 'birth_date', ts('Date of birth'), CRM_Core_SelectValues::date('birth')); $form->addRule('birth_date', ts('Select a valid date.'), 'qfDate'); $form->addElement('text', 'home_URL', ts('Website'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'home_URL')); $form->addRule('home_URL', ts('Enter a valid Website.'), 'url'); $config =& CRM_Core_Config::singleton(); CRM_Core_ShowHideBlocks::links($this, 'demographics', '', ''); }
/** * This function provides the HTML form elements that are specific to the Individual Contact Type * * @access public * @return None */ public function buildQuickForm(&$form, $action = null) { $form->applyFilter('__ALL__', 'trim'); //prefix $prefix = CRM_Core_PseudoConstant::individualPrefix(); if (!empty($prefix)) { $form->addElement('select', 'prefix_id', ts('Prefix'), array('' => '') + $prefix); } $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact'); // first_name $form->addElement('text', 'first_name', ts('First Name'), $attributes['first_name']); //middle_name $form->addElement('text', 'middle_name', ts('Middle Name'), $attributes['middle_name']); // last_name $form->addElement('text', 'last_name', ts('Last Name'), $attributes['last_name']); // suffix $suffix = CRM_Core_PseudoConstant::individualSuffix(); if ($suffix) { $form->addElement('select', 'suffix_id', ts('Suffix'), array('' => '') + $suffix); } // nick_name $form->addElement('text', 'nick_name', ts('Nick Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'nick_name')); // job title // override the size for UI to look better $attributes['job_title']['size'] = 30; $form->addElement('text', 'job_title', ts('Job title'), $attributes['job_title'], 'size="30"'); if ($action & CRM_Core_Action::UPDATE) { $mailToHouseholdID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $form->_contactId, 'mail_to_household_id', 'id'); $form->assign('mailToHouseholdID', $mailToHouseholdID); } //Shared Address Element require_once 'CRM/Contact/BAO/ContactType.php'; if (CRM_Contact_BAO_ContactType::isActive('Household')) { $label = CRM_Contact_BAO_ContactType::getLabel('Household'); $form->addElement('checkbox', 'use_household_address', null, ts('Use %1 Address', array(1 => $label))); } $housholdDataURL = CRM_Utils_System::url('civicrm/ajax/search', "hh=1", false, null, false); $form->assign('housholdDataURL', $housholdDataURL); $form->add('text', 'shared_household', ts('Select Household')); $form->add('hidden', 'shared_household_id', '', array('id' => 'shared_household_id')); //Home Url Element $form->addElement('text', 'home_URL', ts('Website'), array_merge(CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'home_URL'), array('onfocus' => "if (!this.value) this.value='http://'; else return false", 'onblur' => "if ( this.value == 'http://') this.value=''; else return false"))); $form->addRule('home_URL', ts('Enter a valid web location beginning with \'http://\' or \'https://\'. EXAMPLE: http://www.mysite.org/'), 'url'); //Current Employer Element $employerDataURL = CRM_Utils_System::url('civicrm/ajax/contactlist', 'org=1', false, null, false); $form->assign('employerDataURL', $employerDataURL); $form->addElement('text', 'current_employer', ts('Current Employer'), ''); $form->addElement('hidden', 'current_employer_id', '', array('id' => 'current_employer_id')); $form->addElement('text', 'contact_source', ts('Source')); //External Identifier Element $form->add('text', 'external_identifier', ts('External Id'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'), false); $form->addRule('external_identifier', ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier')); $config =& CRM_Core_Config::singleton(); CRM_Core_ShowHideBlocks::links($form, 'demographics', '', ''); }
/** * Create or update a contact (note you should always call this via civicrm_api() & never directly) * * @param array $params input parameters * * Allowed @params array keys are: * {@getfields contact_create} * * * @example ContactCreate.php Example of Create Call * * @return array API Result Array * * @static void * @access public */ function civicrm_api3_contact_create($params) { $contactID = CRM_Utils_Array::value('contact_id', $params, CRM_Utils_Array::value('id', $params)); $dupeCheck = CRM_Utils_Array::value('dupe_check', $params, FALSE); $values = _civicrm_api3_contact_check_params($params, $dupeCheck); if ($values) { return $values; } if (empty($contactID)) { // If we get here, we're ready to create a new contact if (($email = CRM_Utils_Array::value('email', $params)) && !is_array($params['email'])) { require_once 'CRM/Core/BAO/LocationType.php'; $defLocType = CRM_Core_BAO_LocationType::getDefault(); $params['email'] = array(1 => array('email' => $email, 'is_primary' => 1, 'location_type_id' => $defLocType->id ? $defLocType->id : 1)); } } if (CRM_Utils_Array::value('home_url', $params)) { require_once 'CRM/Core/PseudoConstant.php'; $websiteTypes = CRM_Core_PseudoConstant::websiteType(); $params['website'] = array(1 => array('website_type_id' => key($websiteTypes), 'url' => $params['home_url'])); } if (isset($params['suffix_id']) && !is_numeric($params['suffix_id'])) { $params['suffix_id'] = array_search($params['suffix_id'], CRM_Core_PseudoConstant::individualSuffix()); } if (isset($params['prefix_id']) && !is_numeric($params['prefix_id'])) { $params['prefix_id'] = array_search($params['prefix_id'], CRM_Core_PseudoConstant::individualPrefix()); } if (isset($params['gender_id']) && !is_numeric($params['gender_id'])) { $params['gender_id'] = array_search($params['gender_id'], CRM_Core_PseudoConstant::gender()); } $error = _civicrm_api3_greeting_format_params($params); if (civicrm_error($error)) { return $error; } $values = array(); $entityId = $contactID; if (!CRM_Utils_Array::value('contact_type', $params) && $entityId) { $params['contact_type'] = CRM_Contact_BAO_Contact::getContactType($entityId); } if (!isset($params['contact_sub_type']) && $entityId) { require_once 'CRM/Contact/BAO/Contact.php'; $params['contact_sub_type'] = CRM_Contact_BAO_Contact::getContactSubType($entityId); } _civicrm_api3_custom_format_params($params, $values, $params['contact_type'], $entityId); $params = array_merge($params, $values); $contact = _civicrm_api3_contact_update($params, $contactID); if (is_a($contact, 'CRM_Core_Error')) { return civicrm_api3_create_error($contact->_errors[0]['message']); } else { $values = array(); _civicrm_api3_object_to_array_unique_fields($contact, $values[$contact->id]); } return civicrm_api3_create_success($values, $params, 'Contact', 'create'); }
/** * This function provides the HTML form elements that are specific to the Individual Contact Type * * @access public * * @return None */ public function buildQuickForm(&$form, $action = NULL) { $form->applyFilter('__ALL__', 'trim'); //prefix $prefix = CRM_Core_PseudoConstant::individualPrefix(); if (!empty($prefix)) { $form->addElement('select', 'prefix_id', ts('Prefix'), array('' => '') + $prefix); } $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact'); // first_name $form->addElement('text', 'first_name', ts('First Name'), $attributes['first_name']); //middle_name $form->addElement('text', 'middle_name', ts('Middle Name'), $attributes['middle_name']); // last_name $form->addElement('text', 'last_name', ts('Last Name'), $attributes['last_name']); // suffix $suffix = CRM_Core_PseudoConstant::individualSuffix(); if ($suffix) { $form->addElement('select', 'suffix_id', ts('Suffix'), array('' => '') + $suffix); } // nick_name $form->addElement('text', 'nick_name', ts('Nick Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'nick_name')); // job title // override the size for UI to look better $attributes['job_title']['size'] = 30; $form->addElement('text', 'job_title', ts('Job title'), $attributes['job_title'], 'size="30"'); //Current Employer Element $employerDataURL = CRM_Utils_System::url('civicrm/ajax/rest', 'className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=contact&org=1&employee_id=' . $this->_contactId, FALSE, NULL, FALSE); $form->assign('employerDataURL', $employerDataURL); $form->addElement('text', 'current_employer', ts('Current Employer'), ''); $form->addElement('hidden', 'current_employer_id', '', array('id' => 'current_employer_id')); $form->addElement('text', 'contact_source', ts('Source')); $checkSimilar = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_ajax_check_similar', NULL, TRUE); if ($checkSimilar == null) { $checkSimilar = 0; } $form->assign('checkSimilar', $checkSimilar); //External Identifier Element $form->add('text', 'external_identifier', ts('External Id'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'), FALSE); $form->addRule('external_identifier', ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier')); $config = CRM_Core_Config::singleton(); CRM_Core_ShowHideBlocks::links($form, 'demographics', '', ''); }
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; }
/** * Function to actually build the form * * @return void * @access public */ function buildQuickForm() { // add the form elements require_once "CRM/Contribute/PseudoConstant.php"; foreach ($this->_fields as $name => $field) { $required = $field['is_required']; if (substr($field['name'], 0, 14) === 'state_province') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required); } else { if (substr($field['name'], 0, 7) === 'country') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required); } else { if ($field['name'] === 'birth_date') { $this->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('birth'), $required); } else { if ($field['name'] === 'gender') { $genderOptions = array(); $gender = CRM_Core_PseudoConstant::gender(); foreach ($gender as $key => $var) { $genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key); } $this->addGroup($genderOptions, $field['name'], $field['title']); if ($required) { $this->addRule($field['name'], ts('%1 is a required field.', array(1 => $field['title'])), 'required'); } } else { if ($field['name'] === 'individual_prefix') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required); } else { if ($field['name'] === 'individual_suffix') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required); } else { if ($field['name'] === 'preferred_communication_method') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_SelectValues::pcm()); } else { if ($field['name'] === 'preferred_mail_format') { $this->add('select', $name, $field['title'], array(CRM_Core_SelectValues::pcm())); } else { if (substr($field['name'], 0, 7) === 'do_not_') { $this->add('checkbox', $name, $field['title'], $field['attributes'], $required); } else { if ($field['name'] === 'group') { require_once 'CRM/Contact/Form/GroupTag.php'; CRM_Contact_Form_GroupTag::buildGroupTagBlock($this, $this->_id, CRM_CONTACT_FORM_GROUPTAG_GROUP, false, $required, $field['title'], null); } else { if ($field['name'] === 'tag') { require_once 'CRM/Contact/Form/GroupTag.php'; CRM_Contact_Form_GroupTag::buildGroupTagBlock($this, $this->_id, CRM_CONTACT_FORM_GROUPTAG_TAG, false, $required, null, $field['title']); } else { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name'])) { CRM_Core_BAO_CustomField::addQuickFormElement($this, $name, $customFieldID, $inactiveNeeded, $required, false, $field['title']); } else { if (in_array($field['name'], array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) { $this->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('manual', 3, 1), $required); } else { if ($field['name'] == 'payment_instrument') { $this->add('select', 'payment_instrument', ts('Paid By'), array('' => ts('-select-')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required); } else { if ($field['name'] == 'contribution_type') { $this->add('select', 'contribution_type', ts('Contribution Type'), array('' => ts('-select-')) + CRM_Contribute_PseudoConstant::contributionType(), $required); } else { $this->add('text', $name, $field['title'], $field['attributes'], $required); } } } } } } } } } } } } } } } } $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done with Preview'), 'isDefault' => true))); }
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]); }
/** * Function to build the array for display the profile fields * * @param array $params key value. * @param int $gid profile Id * @param array $groupTitle Profile Group Title. * @param array $values formatted array of key value * * @return None * @access public */ function displayProfile(&$params, $gid, &$groupTitle, &$values) { if ($gid) { require_once 'CRM/Core/BAO/UFGroup.php'; require_once 'CRM/Profile/Form.php'; require_once 'CRM/Event/PseudoConstant.php'; $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); if ($contactID) { if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $contactID)) { $fields = CRM_Core_BAO_UFGroup::getFields($gid, false, CRM_Core_Action::VIEW); } } else { $fields = CRM_Core_BAO_UFGroup::getFields($gid, false, CRM_Core_Action::ADD); } if (is_array($fields)) { // unset any email-* fields since we already collect it, CRM-2888 foreach (array_keys($fields) as $fieldName) { if (substr($fieldName, 0, 6) == 'email-') { unset($fields[$fieldName]); } } } foreach ($fields as $v) { if (CRM_Utils_Array::value('groupTitle', $v)) { $groupTitle['groupTitle'] = $v["groupTitle"]; break; } } $config = CRM_Core_Config::singleton(); require_once 'CRM/Core/PseudoConstant.php'; $locationTypes = $imProviders = array(); $locationTypes = CRM_Core_PseudoConstant::locationType(); $imProviders = CRM_Core_PseudoConstant::IMProvider(); //start of code to set the default values foreach ($fields as $name => $field) { $index = $field['title']; $customFieldName = null; if ($name === 'organization_name') { $values[$index] = $params[$name]; } if ('state_province' == substr($name, 0, 14)) { if ($params[$name]) { $values[$index] = CRM_Core_PseudoConstant::stateProvince($params[$name]); } else { $values[$index] = ''; } } else { if ('country' == substr($name, 0, 7)) { if ($params[$name]) { $values[$index] = CRM_Core_PseudoConstant::country($params[$name]); } else { $values[$index] = ''; } } else { if ('county' == substr($name, 0, 6)) { if ($params[$name]) { $values[$index] = CRM_Core_PseudoConstant::county($params[$name]); } else { $values[$index] = ''; } } else { if ('gender' == substr($name, 0, 6)) { $gender = CRM_Core_PseudoConstant::gender(); $values[$index] = $gender[$params[$name]]; } else { if ('individual_prefix' == substr($name, 0, 17)) { $prefix = CRM_Core_PseudoConstant::individualPrefix(); $values[$index] = $prefix[$params[$name]]; } else { if ('individual_suffix' == substr($name, 0, 17)) { $suffix = CRM_Core_PseudoConstant::individualSuffix(); $values[$index] = $suffix[$params[$name]]; } else { if (in_array($name, array('addressee', 'email_greeting', 'postal_greeting'))) { $filterCondition = array('greeting_type' => $name); $greeting =& CRM_Core_PseudoConstant::greeting($filterCondition); $values[$index] = $greeting[$params[$name]]; } else { if ($name === 'preferred_communication_method') { $communicationFields = CRM_Core_PseudoConstant::pcm(); $pref = array(); $compref = array(); $pref = $params[$name]; if (is_array($pref)) { foreach ($pref as $k => $v) { if ($v) { $compref[] = $communicationFields[$k]; } } } $values[$index] = implode(",", $compref); } else { if ($name == 'group') { require_once 'CRM/Contact/BAO/GroupContact.php'; $groups = CRM_Contact_BAO_GroupContact::getGroupList(); $title = array(); foreach ($params[$name] as $gId => $dontCare) { if ($dontCare) { $title[] = $groups[$gId]; } } $values[$index] = implode(', ', $title); } else { if ($name == 'tag') { require_once 'CRM/Core/BAO/EntityTag.php'; $entityTags = $params[$name]; $allTags =& CRM_Core_PseudoConstant::tag(); $title = array(); if (is_array($entityTags)) { foreach ($entityTags as $tagId => $dontCare) { $title[] = $allTags[$tagId]; } } $values[$index] = implode(', ', $title); } else { if ('participant_role_id' == $name) { $roles = CRM_Event_PseudoConstant::participantRole(); $values[$index] = $roles[$params[$name]]; } else { if ('participant_status_id' == $name) { $status = CRM_Event_PseudoConstant::participantStatus(); $values[$index] = $status[$params[$name]]; } else { if (strpos($name, '-') !== false) { list($fieldName, $id) = CRM_Utils_System::explode('-', $name, 2); $detailName = str_replace(' ', '_', $name); if (in_array($fieldName, array('state_province', 'country', 'county'))) { $values[$index] = $params[$detailName]; $idx = $detailName . '_id'; $values[$index] = $params[$idx]; } else { if ($fieldName == 'im') { $providerName = null; if ($providerId = $detailName . '-provider_id') { $providerName = CRM_Utils_Array::value($params[$providerId], $imProviders); } if ($providerName) { $values[$index] = $params[$detailName] . " (" . $providerName . ")"; } else { $values[$index] = $params[$detailName]; } } else { $values[$index] = $params[$detailName]; } } } else { if (substr($name, 0, 7) === 'do_not_' or substr($name, 0, 3) === 'is_') { if ($params[$name]) { $values[$index] = '[ x ]'; } } else { require_once 'CRM/Core/BAO/CustomField.php'; if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) { $query = "\nSELECT html_type, data_type\nFROM civicrm_custom_field\nWHERE id = {$cfID}\n"; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); $dao->fetch(); $htmlType = $dao->html_type; $dataType = $dao->data_type; if ($htmlType == 'File') { //$fileURL = CRM_Core_BAO_CustomField::getFileURL( $contactID, $cfID ); //$params[$index] = $values[$index] = $fileURL['file_url']; $values[$index] = $params[$index]; } else { if ($dao->data_type == 'Int' || $dao->data_type == 'Boolean') { $customVal = (int) $params[$name]; } else { if ($dao->data_type == 'Float') { $customVal = (double) $params[$name]; } else { if ($dao->data_type == 'Date') { $date = CRM_Utils_Date::format($params[$name], null, 'invalidDate'); if ($date != 'invalidDate') { $customVal = $date; } } else { $customVal = $params[$name]; } } } //take the custom field options $returnProperties = array($name => 1); require_once 'CRM/Contact/BAO/Query.php'; $query = new CRM_Contact_BAO_Query($params, $returnProperties, $fields); $options =& $query->_options; $displayValue = CRM_Core_BAO_CustomField::getDisplayValue($customVal, $cfID, $options); //Hack since we dont have function to check empty. //FIXME in 2.3 using crmIsEmptyArray() $customValue = true; if (is_array($customVal) && is_array($displayValue)) { $customValue = array_diff($customVal, $displayValue); } //use difference of arrays if (empty($customValue) || !$customValue) { $values[$index] = ''; } else { $values[$index] = $displayValue; } if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $cfID, 'is_search_range')) { $customFieldName = "{$name}_from"; } } } else { if ($name == 'home_URL' && !empty($params[$name])) { $url = CRM_Utils_System::fixURL($params[$name]); $values[$index] = "<a href=\"{$url}\">{$params[$name]}</a>"; } else { if (in_array($name, array('birth_date', 'deceased_date', 'participant_register_date'))) { require_once 'CRM/Utils/Date.php'; $values[$index] = CRM_Utils_Date::customFormat(CRM_Utils_Date::format($params[$name])); } else { $values[$index] = $params[$name]; } } } } } } } } } } } } } } } } } } } }
/** * creates display name * * @return string the constructed display name */ function displayName() { $prefix =& CRM_Core_PseudoConstant::individualPrefix(); $suffix =& CRM_Core_PseudoConstant::individualSuffix(); return str_replace(' ', ' ', trim($prefix[$this->prefix_id] . ' ' . $this->first_name . ' ' . $this->middle_name . ' ' . $this->last_name . ' ' . $suffix[$this->suffix_id])); }
/** * @todo Write sth * @todo Serious FIXMES in the code! File issues. */ function civicrm_contact_update(&$params, $create_new = FALSE) { _civicrm_initialize(); try { civicrm_api_check_permission(__FUNCTION__, $params, TRUE); } catch (Exception $e) { return civicrm_create_error($e->getMessage()); } require_once 'CRM/Utils/Array.php'; $entityId = CRM_Utils_Array::value('contact_id', $params, NULL); if (!CRM_Utils_Array::value('contact_type', $params) && $entityId) { $params['contact_type'] = CRM_Contact_BAO_Contact::getContactType($entityId); } $dupeCheck = CRM_Utils_Array::value('dupe_check', $params, FALSE); $values = civicrm_contact_check_params($params, $dupeCheck); if ($values) { return $values; } if ($create_new) { // Make sure nothing is screwed up before we create a new contact if (!empty($entityId)) { return civicrm_create_error('Cannot create new contact when contact_id is present'); } if (empty($params['contact_type'])) { return civicrm_create_error('Contact Type not specified'); } // If we get here, we're ready to create a new contact if (($email = CRM_Utils_Array::value('email', $params)) && !is_array($params['email'])) { require_once 'CRM/Core/BAO/LocationType.php'; $defLocType = CRM_Core_BAO_LocationType::getDefault(); $params['email'] = array(1 => array('email' => $email, 'is_primary' => 1, 'location_type_id' => $defLocType->id ? $defLocType->id : 1)); } } if ($homeUrl = CRM_Utils_Array::value('home_url', $params)) { require_once 'CRM/Core/PseudoConstant.php'; $websiteTypes = CRM_Core_PseudoConstant::websiteType(); $params['website'] = array(1 => array('website_type_id' => key($websiteTypes), 'url' => $homeUrl)); } // FIXME: Some legacy support cruft, should get rid of this in 3.1 $change = array('individual_prefix' => 'prefix', 'prefix' => 'prefix_id', 'individual_suffix' => 'suffix', 'suffix' => 'suffix_id', 'gender' => 'gender_id'); foreach ($change as $field => $changeAs) { if (array_key_exists($field, $params)) { $params[$changeAs] = $params[$field]; unset($params[$field]); } } // End legacy support cruft if (isset($params['suffix_id']) && !is_numeric($params['suffix_id'])) { $params['suffix_id'] = array_search($params['suffix_id'], CRM_Core_PseudoConstant::individualSuffix()); } if (isset($params['prefix_id']) && !is_numeric($params['prefix_id'])) { $params['prefix_id'] = array_search($params['prefix_id'], CRM_Core_PseudoConstant::individualPrefix()); } if (isset($params['gender_id']) && !is_numeric($params['gender_id'])) { $params['gender_id'] = array_search($params['gender_id'], CRM_Core_PseudoConstant::gender()); } $error = _civicrm_greeting_format_params($params); if (civicrm_error($error)) { return $error; } $values = array(); if (!($csType = CRM_Utils_Array::value('contact_sub_type', $params)) && $entityId) { require_once 'CRM/Contact/BAO/Contact.php'; $csType = CRM_Contact_BAO_Contact::getContactSubType($entityId); } $customValue = civicrm_contact_check_custom_params($params, $csType); if ($customValue) { return $customValue; } _civicrm_custom_format_params($params, $values, $params['contact_type'], $entityId); $params = array_merge($params, $values); $contact =& _civicrm_contact_update($params, $entityId); if (is_a($contact, 'CRM_Core_Error')) { return civicrm_create_error($contact->_errors[0]['message']); } else { $values = array(); $values['contact_id'] = $contact->id; $values['is_error'] = 0; } return $values; }
/** * Function to build form for related contacts / on behalf of organization. * * @param $form object invoking Object * @param $contactType string contact type * @param $title string fieldset title * @param $maxLocationBlocks int number of location blocks * * @static * */ static function buildOnBehalfForm(&$form, $contactType = 'Individual', $countryID = null, $stateID = null, $title = 'Contact Information', $contactEditMode = false, $maxLocationBlocks = 1) { if ($title == 'Contact Information') { $title = ts('Contact Information'); } require_once 'CRM/Contact/Form/Location.php'; $config = CRM_Core_Config::singleton(); $form->assign('contact_type', $contactType); $form->assign('fieldSetTitle', $title); $form->assign('contactEditMode', $contactEditMode); $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact'); switch ($contactType) { case 'Organization': $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); if ($contactID) { require_once 'CRM/Contact/BAO/Relationship.php'; $employers = CRM_Contact_BAO_Relationship::getPermissionedEmployer($contactID); } if (!$contactEditMode && $contactID && count($employers) >= 1) { $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', "cid=", false, null, false); $form->assign('locDataURL', $locDataURL); $dataURL = CRM_Utils_System::url('civicrm/ajax/employer', "cid=" . $contactID, false, null, false); $form->assign('employerDataURL', $dataURL); $form->add('text', 'organization_id', ts('Select an existing related Organization OR Enter a new one')); $form->add('hidden', 'onbehalfof_id', '', array('id' => 'onbehalfof_id')); $orgOptions = array('0' => ts('Create new organization'), '1' => ts('Select existing organization')); $orgOptionExtra = array('onclick' => "showHideByValue('org_option','true','select_org','table-row','radio',true);showHideByValue('org_option','true','create_org','table-row','radio',false);"); $form->addRadio('org_option', ts('options'), $orgOptions, $orgOptionExtra); $form->assign('relatedOrganizationFound', true); } $isRequired = false; if (CRM_Utils_Array::value('is_for_organization', $form->_values) == 2) { $isRequired = true; } $form->add('text', 'organization_name', ts('Organization Name'), $attributes['organization_name'], $isRequired); break; case 'Household': $form->add('text', 'household_name', ts('Household Name'), $attributes['household_name']); break; default: // individual $form->addElement('select', 'prefix_id', ts('Prefix'), array('' => ts('- prefix -')) + CRM_Core_PseudoConstant::individualPrefix()); $form->addElement('text', 'first_name', ts('First Name'), $attributes['first_name']); $form->addElement('text', 'middle_name', ts('Middle Name'), $attributes['middle_name']); $form->addElement('text', 'last_name', ts('Last Name'), $attributes['last_name']); $form->addElement('select', 'suffix_id', ts('Suffix'), array('' => ts('- suffix -')) + CRM_Core_PseudoConstant::individualSuffix()); } $addressSequence = $config->addressSequence(); $form->assign('addressSequence', array_fill_keys($addressSequence, 1)); //Primary Phone $form->addElement('text', "phone[1][phone]", ts('Primary Phone'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone')); //Primary Email $form->addElement('text', "email[1][email]", ts('Primary Email'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', 'email')); //build the address block require_once 'CRM/Contact/Form/Edit/Address.php'; CRM_Contact_Form_Edit_Address::buildQuickForm($form); // also fix the state country selector CRM_Contact_Form_Edit_Address::fixStateSelect($form, "address[1][country_id]", "address[1][state_province_id]", $countryID); }
/** * Get all Individual Suffix. * * The static array individualSuffix is returned * * @access public * @static * * @param boolean $all - get All Individual Suffix - default is to get only active ones. * * @return array - array reference of all individual suffix. * */ public static function &individualSuffix() { if (!self::$individualSuffix) { self::$individualSuffix = CRM_Core_OptionGroup::values('individual_suffix'); } return self::$individualSuffix; }
/** * * Get the values for pseudoconstants for name->value and reverse. * * @param array $defaults (reference) the default values, some of which need to be resolved. * @param boolean $reverse true if we want to resolve the values in the reverse direction (value -> name) * * @return none * @access public * @static */ static function resolveDefaults(&$defaults, $reverse = FALSE) { // hack for birth_date if (CRM_Utils_Array::value('birth_date', $defaults)) { if (is_array($defaults['birth_date'])) { $defaults['birth_date'] = CRM_Utils_Date::format($defaults['birth_date'], '-'); } } CRM_Utils_Array::lookupValue($defaults, 'prefix', CRM_Core_PseudoConstant::individualPrefix(), $reverse); CRM_Utils_Array::lookupValue($defaults, 'suffix', CRM_Core_PseudoConstant::individualSuffix(), $reverse); CRM_Utils_Array::lookupValue($defaults, 'gender', CRM_Core_PseudoConstant::gender(), $reverse); //lookup value of email/postal greeting, addressee, CRM-4575 foreach (self::$_greetingTypes as $greeting) { $filterCondition = array('contact_type' => CRM_Utils_Array::value('contact_type', $defaults), 'greeting_type' => $greeting); CRM_Utils_Array::lookupValue($defaults, $greeting, CRM_Core_PseudoConstant::greeting($filterCondition), $reverse); } $blocks = array('address', 'im', 'phone'); foreach ($blocks as $name) { if (!array_key_exists($name, $defaults) || !is_array($defaults[$name])) { continue; } foreach ($defaults[$name] as $count => &$values) { //get location type id. CRM_Utils_Array::lookupValue($values, 'location_type', CRM_Core_PseudoConstant::locationType(), $reverse); if ($name == 'address') { // FIXME: lookupValue doesn't work for vcard_name if (CRM_Utils_Array::value('location_type_id', $values)) { $vcardNames = CRM_Core_PseudoConstant::locationVcardName(); $values['vcard_name'] = $vcardNames[$values['location_type_id']]; } if (!CRM_Utils_Array::lookupValue($values, 'country', CRM_Core_PseudoConstant::country(), $reverse) && $reverse) { CRM_Utils_Array::lookupValue($values, 'country', CRM_Core_PseudoConstant::countryIsoCode(), $reverse); } // CRM-7597 // if we find a country id above, we need to restrict it to that country // rather than the list of all countries if (!empty($values['country_id'])) { $stateProvinceList = CRM_Core_PseudoConstant::stateProvinceForCountry($values['country_id']); } else { $stateProvinceList = CRM_Core_PseudoConstant::stateProvince(); } if (!CRM_Utils_Array::lookupValue($values, 'state_province', $stateProvinceList, $reverse) && $reverse) { if (!empty($values['country_id'])) { $stateProvinceList = CRM_Core_PseudoConstant::stateProvinceForCountry($values['country_id'], 'abbreviation'); } else { $stateProvinceList = CRM_Core_PseudoConstant::stateProvinceAbbreviation(); } CRM_Utils_Array::lookupValue($values, 'state_province', $stateProvinceList, $reverse); } if (!empty($values['state_province_id'])) { $countyList = CRM_Core_PseudoConstant::countyForState($values['state_province_id']); } else { $countyList = CRM_Core_PseudoConstant::county(); } CRM_Utils_Array::lookupValue($values, 'county', $countyList, $reverse); } if ($name == 'im') { CRM_Utils_Array::lookupValue($values, 'provider', CRM_Core_PseudoConstant::IMProvider(), $reverse); } if ($name == 'phone') { CRM_Utils_Array::lookupValue($values, 'phone_type', CRM_Core_PseudoConstant::phoneType(), $reverse); } //kill the reference. unset($values); } } }
/** * Function to actually build the form * * @return void * @access public */ function buildQuickForm() { if ($this->_mode != CRM_PROFILE_FORM_MODE_REGISTER) { //check for mix profile (eg: individual + other contact type) require_once "CRM/Core/BAO/UFField.php"; if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) { CRM_Utils_System::setUFMessage(ts("This Profile includes fields for contact types other than 'Individuals' and can not be used to create/update contacts.")); $config =& CRM_Core_Config::singleton(); CRM_Utils_System::redirect($config->userFrameworkBaseURL); } } $this->assign('mode', $this->_mode); $this->assign('action', $this->_action); $this->assign('fields', $this->_fields); $this->assign('fieldset', $this->_fieldset); /* if ($this->_mode & self::MODE_EDIT) { $group =& new CRM_Core_DAO_UFGroup(); $group->id = $this->_gid; if ($group->find(true)) { $this->assign('help_pre', $group->help_pre); $this->assign('help_post', $group->help_post); } }*/ // do we need inactive options ? if ($this->_action & CRM_CORE_ACTION_VIEW) { $inactiveNeeded = true; } else { $inactiveNeeded = false; } // should we restrict what we display $admin = true; if ($this->_mode == CRM_PROFILE_FORM_MODE_EDIT) { $admin = false; $session =& CRM_Core_Session::singleton(); // show all fields that are visibile: if we are a admin or the same user or in registration mode if (CRM_Utils_System::checkPermission('administer users') || $this->_id == $session->get('userID')) { $admin = true; } } require_once "CRM/Contribute/PseudoConstant.php"; // add the form elements foreach ($this->_fields as $name => $field) { // make sure that there is enough permission to expose this field if (!$admin && $field['visibility'] == 'User and User Admin Only') { unset($this->_fields[$name]); continue; } // since the CMS manages the email field, suppress the email display if in // register mode which occur within the CMS form if ($this->_mode == CRM_PROFILE_FORM_MODE_REGISTER && substr($name, 0, 5) == 'email') { unset($this->_fields[$name]); continue; } $required = $this->_mode == CRM_PROFILE_FORM_MODE_SEARCH ? false : $field['is_required']; //if ( $field['name'] === 'state_province' ) { if (substr($field['name'], 0, 14) === 'state_province') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required); } else { if (substr($field['name'], 0, 7) === 'country') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required); } else { if ($field['name'] === 'birth_date') { $this->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('birth'), $required); } else { if ($field['name'] === 'gender') { $genderOptions = array(); $gender = CRM_Core_PseudoConstant::gender(); foreach ($gender as $key => $var) { $genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key); } $this->addGroup($genderOptions, $field['name'], $field['title']); if ($required) { $this->addRule($field['name'], ts('%1 is a required field.', array(1 => $field['title'])), 'required'); } } else { if ($field['name'] === 'individual_prefix') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required); } else { if ($field['name'] === 'individual_suffix') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required); } else { if ($field['name'] === 'preferred_communication_method') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_SelectValues::pcm()); } else { if ($field['name'] === 'preferred_mail_format') { $this->add('select', $name, $field['title'], CRM_Core_SelectValues::pmf()); } else { if (substr($field['name'], 0, 3) === 'is_' or substr($field['name'], 0, 7) === 'do_not_') { $this->add('checkbox', $name, $field['title'], $field['attributes'], $required); } else { if ($field['name'] === 'group') { require_once 'CRM/Contact/Form/GroupTag.php'; CRM_Contact_Form_GroupTag::buildGroupTagBlock($this, $this->_id, CRM_CONTACT_FORM_GROUPTAG_GROUP, true, $required, $field['title'], null); } else { if ($field['name'] === 'tag') { require_once 'CRM/Contact/Form/GroupTag.php'; CRM_Contact_Form_GroupTag::buildGroupTagBlock($this, $this->_id, CRM_CONTACT_FORM_GROUPTAG_TAG, false, $required, null, $field['title']); } else { if (substr($field['name'], 0, 6) === 'custom') { $customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name']); CRM_Core_BAO_CustomField::addQuickFormElement($this, $name, $customFieldID, $inactiveNeeded, $required, false, $field['title']); CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, $this->_id, $this->_mode); } else { if (in_array($field['name'], array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) { $this->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('manual', 3, 1), $required); $this->addRule($field['name'], ts('Select a valid date.'), 'qfDate'); } else { if ($field['name'] == 'payment_instrument') { $this->add('select', 'payment_instrument', ts('Paid By'), array('' => ts('-select-')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required); } else { if ($field['name'] == 'contribution_type') { $this->add('select', 'contribution_type', ts('Contribution Type'), array('' => ts('-select-')) + CRM_Contribute_PseudoConstant::contributionType(), $required); } else { $this->add('text', $name, $field['title'], $field['attributes'], $required); } } } } } } } } } } } } } } } if (in_array($field['name'], array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) { $this->addRule($field['name'], ts('Please enter a valid amount.'), 'money'); } if ($field['rule']) { if ($field['rule'] == 'email' && $this->_mode == CRM_PROFILE_FORM_MODE_SEARCH) { continue; } else { $this->addRule($name, ts('Please enter a valid %1', array(1 => $field['title'])), $field['rule']); } } } // if view mode pls freeze it with the done button. if ($this->_action & CRM_CORE_ACTION_VIEW) { $this->freeze(); } $this->setDefaults($defaults); }
/** * @todo Write sth * @todo Serious FIXMES in the code! File issues. */ function civicrm_contact_update(&$params, $create_new = false) { _civicrm_initialize(); require_once 'CRM/Utils/Array.php'; $contactID = CRM_Utils_Array::value('contact_id', $params); if ($create_new) { // Make sure nothing is screwed up before we create a new contact if (!empty($contactID)) { return civicrm_create_error('Cannot create new contact when contact_id is present'); } if (empty($params['contact_type'])) { return civicrm_create_error('Contact Type not specified'); } $dupeCheck = CRM_Utils_Array::value('dupe_check', $params, false); $values = civicrm_contact_check_params($params, $dupeCheck); if ($values) { return $values; } // If we get here, we're ready to create a new contact if (($email = CRM_Utils_Array::value('email', $params)) && !is_array($params['email'])) { require_once 'CRM/Core/BAO/LocationType.php'; $defLocType = CRM_Core_BAO_LocationType::getDefault(); $params['email'] = array(1 => array('email' => $email, 'is_primary' => 1, 'location_type_id' => $defLocType->id ? $defLocType->id : 1)); } } // FIXME: Some legacy support cruft, should get rid of this in 3.1 $change = array('individual_prefix' => 'prefix', 'prefix' => 'prefix_id', 'individual_suffix' => 'suffix', 'suffix' => 'suffix_id', 'gender' => 'gender_id'); foreach ($change as $field => $changeAs) { if (array_key_exists($field, $params)) { $params[$changeAs] = $params[$field]; unset($params[$field]); } } // End legacy support cruft if (isset($params['suffix_id']) && !is_numeric($params['suffix_id'])) { $params['suffix_id'] = array_search($params['suffix_id'], CRM_Core_PseudoConstant::individualSuffix()); } if (isset($params['prefix_id']) && !is_numeric($params['prefix_id'])) { $params['prefix_id'] = array_search($params['prefix_id'], CRM_Core_PseudoConstant::individualPrefix()); } if (isset($params['gender_id']) && !is_numeric($params['gender_id'])) { $params['gender_id'] = array_search($params['gender_id'], CRM_Core_PseudoConstant::gender()); } $values = array(); $entityId = CRM_Utils_Array::value('contact_id', $params, null); _civicrm_custom_format_params($params, $values, $params['contact_type'], $entityId); $params = array_merge($params, $values); $contact =& _civicrm_contact_update($params, $contactID); if (is_a($contact, 'CRM_Core_Error')) { return civicrm_create_error($contact->_errors[0]['message']); } else { $values = array(); $values['contact_id'] = $contact->id; $values['is_error'] = 0; } return $values; }
/** * Get all Individual Suffix. * * The static array individualSuffix is returned * * @access public * @static * * @param boolean $all - get All Individual Suffix - default is to get only active ones. * * @return array - array reference of all individual suffix. * */ public static function &individualSuffix() { if (!self::$individualSuffix) { require_once 'CRM/Core/OptionGroup.php'; self::$individualSuffix = CRM_Core_OptionGroup::values('individual_suffix'); } return self::$individualSuffix; }
/** * test case for getDisplayAndImage( ) * */ function testGetDisplayAndImage() { //get the contact params $params = $this->contactParams(); //create contact require_once 'CRM/Contact/BAO/Contact.php'; $contact = CRM_Contact_BAO_Contact::create($params); $contactId = $contact->id; //get DisplayAndImage. list($displayName, $image) = CRM_Contact_BAO_Contact::getDisplayAndImage($contactId); require_once 'CRM/Contact/BAO/Contact/Utils.php'; $checkImage = CRM_Contact_BAO_Contact_Utils::getImage($params['contact_type']); require_once 'CRM/Core/PseudoConstant.php'; $prefix = CRM_Core_PseudoConstant::individualPrefix(); $suffix = CRM_Core_PseudoConstant::individualSuffix(); //build display name $paramsDisplayName = $prefix[$params['prefix_id']] . ' ' . $params['first_name'] . ' ' . $params['middle_name'] . ' ' . $params['last_name'] . ' ' . $suffix[$params['suffix_id']]; $this->assertEquals($displayName, $paramsDisplayName, 'Check For Display Name'); $this->assertEquals($image, $checkImage, 'Check For Image'); //cleanup DB by deleting the contact Contact::delete($contactId); }
/** * build a form for the given UF group * * @param int $id the group id * @param CRM_Core_Form $form the form element * @param string $name the name that we should store the fields as * @param array $allFields reference to the array where all the fields are stored * * @return void * @static * @access public */ function buildQuickForm($id, &$form, $name, &$allFields) { $fields =& CRM_Core_BAO_UFGroup::getFields($id, false, $action); foreach ($fields as $n => $fld) { if (!array_key_exists($n, $allFields)) { $allFields[$n] = $fld; } } $form->assign($name, $fields); foreach ($fields as $name => $field) { $required = $field['is_required']; if (substr($field['name'], 0, 14) === 'state_province') { $form->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required); } else { if (substr($field['name'], 0, 7) === 'country') { $form->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required); } else { if ($field['name'] === 'birth_date') { $form->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('birth')); } else { if ($field['name'] === '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, $field['name'], $field['title']); } else { if ($field['name'] === 'individual_prefix') { $form->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix()); } else { if ($field['name'] === 'individual_suffix') { $form->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix()); } else { if ($field['name'] === 'group') { require_once 'CRM/Contact/Form/GroupTag.php'; CRM_Contact_Form_GroupTag::buildGroupTagBlock($form, 0, CRM_CONTACT_FORM_GROUPTAG_GROUP); } else { if ($field['name'] === 'tag') { require_once 'CRM/Contact/Form/GroupTag.php'; CRM_Contact_Form_GroupTag::buildGroupTagBlock($form, 0, CRM_CONTACT_FORM_GROUPTAG_TAG); } else { if (substr($field['name'], 0, 6) === 'custom') { $customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name']); CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, $inactiveNeeded, false); if ($required) { $form->addRule($name, ts('%1 is a required field.', array(1 => $field['title'])), 'required'); } } else { $form->add('text', $name, $field['title'], $field['attributes'], $required); } } } } } } } } } if ($field['rule']) { $form->addRule($name, ts('Please enter a valid %1', array(1 => $field['title'])), $field['rule']); } } }
/** * * Get the values for pseudoconstants for name->value and reverse. * * @param array $defaults (reference) the default values, some of which need to be resolved. * @param boolean $reverse true if we want to resolve the values in the reverse direction (value -> name) * * @return none * @access public * @static */ static function resolveDefaults(&$defaults, $reverse = false) { // hack for birth_date if (CRM_Utils_Array::value('birth_date', $defaults)) { if (is_array($defaults['birth_date'])) { $defaults['birth_date'] = CRM_Utils_Date::format($defaults['birth_date'], '-'); } } CRM_Utils_Array::lookupValue($defaults, 'prefix', CRM_Core_PseudoConstant::individualPrefix(), $reverse); CRM_Utils_Array::lookupValue($defaults, 'suffix', CRM_Core_PseudoConstant::individualSuffix(), $reverse); CRM_Utils_Array::lookupValue($defaults, 'gender', CRM_Core_PseudoConstant::gender(), $reverse); //lookup value of email/postal greeting, addressee, CRM-4575 $filterCondition = array('contact_type' => CRM_Utils_Array::value('contact_type', $defaults), 'greeting_type' => 'email_greeting'); CRM_Utils_Array::lookupValue($defaults, 'email_greeting', CRM_Core_PseudoConstant::greeting($filterCondition), $reverse); $filterCondition = array('contact_type' => CRM_Utils_Array::value('contact_type', $defaults), 'greeting_type' => 'postal_greeting'); CRM_Utils_Array::lookupValue($defaults, 'postal_greeting', CRM_Core_PseudoConstant::greeting($filterCondition), $reverse); $filterCondition = array('contact_type' => CRM_Utils_Array::value('contact_type', $defaults), 'greeting_type' => 'addressee'); CRM_Utils_Array::lookupValue($defaults, 'addressee', CRM_Core_PseudoConstant::greeting($filterCondition), $reverse); $blocks = array('address', 'im', 'phone'); foreach ($blocks as $name) { if (!array_key_exists($name, $defaults) || !is_array($defaults[$name])) { continue; } foreach ($defaults[$name] as $count => &$values) { //get location type id. CRM_Utils_Array::lookupValue($values, 'location_type', CRM_Core_PseudoConstant::locationType(), $reverse); if ($name == 'address') { // FIXME: lookupValue doesn't work for vcard_name if (CRM_Utils_Array::value('location_type_id', $values)) { $vcardNames =& CRM_Core_PseudoConstant::locationVcardName(); $values['vcard_name'] = $vcardNames[$values['location_type_id']]; } if (!CRM_Utils_Array::lookupValue($values, 'state_province', CRM_Core_PseudoConstant::stateProvince(), $reverse) && $reverse) { CRM_Utils_Array::lookupValue($values, 'state_province', CRM_Core_PseudoConstant::stateProvinceAbbreviation(), $reverse); } if (!CRM_Utils_Array::lookupValue($values, 'country', CRM_Core_PseudoConstant::country(), $reverse) && $reverse) { CRM_Utils_Array::lookupValue($values, 'country', CRM_Core_PseudoConstant::countryIsoCode(), $reverse); } CRM_Utils_Array::lookupValue($values, 'county', CRM_Core_PseudoConstant::county(), $reverse); } if ($name == 'im') { CRM_Utils_Array::lookupValue($values, 'provider', CRM_Core_PseudoConstant::IMProvider(), $reverse); } if ($name == 'phone') { CRM_Utils_Array::lookupValue($values, 'phone_type', CRM_Core_PseudoConstant::phoneType(), $reverse); } //kill the reference. unset($values); } } }
/** * 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; } 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, 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') { require_once 'CRM/Member/PseudoConstant.php'; $form->add('select', 'status_id', $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(), $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 == '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 ($fieldName === 'home_URL') { $form->addElement('text', $name, $title, array_merge(CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'home_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'); } 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 (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 == '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), $required); } else { if ($fieldName == 'participant_role_id') { require_once "CRM/Event/PseudoConstant.php"; $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 { $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); } } }
/** * function to check if an error in Core( non-custom fields ) field * * @param String $errorMessage A string containing all the error-fields. * * @access public */ function isErrorInCoreData($params, &$errorMessage) { foreach ($params as $key => $value) { if ($value) { switch ($key) { case 'birth_date': if (!CRM_Utils_Rule::date($value)) { //return _crm_error('Birth Date'); CRM_Import_Parser_Contact::addToErrorMsg('Birth Date', $errorMessage); } break; case 'gender': if (!CRM_Import_Parser_Contact::in_value($value, CRM_Core_PseudoConstant::gender(true))) { //return _crm_error('Invalid value for field : Gender'); CRM_Import_Parser_Contact::addToErrorMsg('Gender', $errorMessage); } break; case 'preferred_communication_method': if (!array_key_exists(strtolower($value), array_change_key_case(CRM_Core_SelectValues::pcm(), CASE_LOWER))) { //return _crm_error('Invalid value for field : Preferred Communication Method'); CRM_Import_Parser_Contact::addToErrorMsg('Preferred Communication Method', $errorMessage); } break; case 'preferred_mail_format': if (!array_key_exists(strtolower($value), array_change_key_case(CRM_Core_SelectValues::pmf(), CASE_LOWER))) { //return _crm_error('Invalid value for field : Preferred Communication Method'); CRM_Import_Parser_Contact::addToErrorMsg('Preferred Mail Format', $errorMessage); } break; case 'individual_prefix': if (!CRM_Import_Parser_Contact::in_value($value, CRM_Core_PseudoConstant::individualPrefix(true))) { //return _crm_error('Invalid value for field : Individual Prefix'); CRM_Import_Parser_Contact::addToErrorMsg('Individual Prefix', $errorMessage); } break; case 'individual_suffix': if (!CRM_Import_Parser_Contact::in_value($value, CRM_Core_PseudoConstant::individualSuffix(true))) { //return _crm_error('Invalid value for field : Individual Suffix'); CRM_Import_Parser_Contact::addToErrorMsg('Individual Suffix', $errorMessage); } break; case 'state_province': if (!empty($value)) { foreach ($value as $stateValue) { if ($stateValue['state_province']) { if (CRM_Import_Parser_Contact::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvinceAbbreviation()) || CRM_Import_Parser_Contact::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvince())) { continue; } else { //return _crm_error('Invalid value for field : State Province '); CRM_Import_Parser_Contact::addToErrorMsg('State Province', $errorMessage); } } } } break; case 'country': if (!empty($value)) { foreach ($value as $stateValue) { if ($stateValue['country']) { if (CRM_Import_Parser_Contact::in_value($stateValue['country'], CRM_Core_PseudoConstant::countryIsoCode()) || CRM_Import_Parser_Contact::in_value($stateValue['country'], CRM_Core_PseudoConstant::country())) { continue; } else { //return _crm_error('Invalid value for field : Country'); CRM_Import_Parser_Contact::addToErrorMsg('Country', $errorMessage); } } } } break; case 'geo_code_1': if (!empty($value)) { foreach ($value as $codeValue) { if ($codeValue['geo_code_1']) { if (CRM_Utils_Rule::numeric($codeValue['geo_code_1'])) { continue; } else { //return _crm_error('Invalid value for field : geo_code_1'); CRM_Import_Parser_Contact::addToErrorMsg('geo_code_1', $errorMessage); } } } } break; case 'geo_code_2': if (!empty($value)) { foreach ($value as $codeValue) { if ($codeValue['geo_code_2']) { if (CRM_Utils_Rule::numeric($codeValue['geo_code_2'])) { continue; } else { //return _crm_error('Invalid value for field : geo_code_2'); CRM_Import_Parser_Contact::addToErrorMsg('geo_code_2', $errorMessage); } } } } } } } //return true; }
/** * 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, ' ', 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); } } }
/** * This function adds the contact variable in $values to the * parameter list $params. For most cases, $values should have length 1. If * the variable being added is a child of Location, a location_type_id must * also be included. If it is a child of phone, a phone_type must be included. * * @param array $values The variable(s) to be added * @param array $params The structured parameter list * * @return bool|CRM_Utils_Error * @access public */ function _civicrm_add_formatted_param(&$values, &$params) { /* Crawl through the possible classes: * Contact * Individual * Household * Organization * Location * Address * Email * Phone * IM * Note * Custom */ /* Cache the various object fields */ static $fields = null; if ($fields == null) { $fields = array(); } //first add core contact values since for other Civi modules they are not added require_once 'CRM/Contact/BAO/Contact.php'; $contactFields =& CRM_Contact_DAO_Contact::fields(); _civicrm_store_values($contactFields, $values, $params); if (isset($values['contact_type'])) { /* we're an individual/household/org property */ $fields[$values['contact_type']] = CRM_Contact_DAO_Contact::fields(); _civicrm_store_values($fields[$values['contact_type']], $values, $params); return true; } if (isset($values['individual_prefix'])) { if ($params['prefix_id']) { $prefixes = array(); $prefixes = CRM_Core_PseudoConstant::individualPrefix(); $params['prefix'] = $prefixes[$params['prefix_id']]; } else { $params['prefix'] = $values['individual_prefix']; } return true; } if (isset($values['individual_suffix'])) { if ($params['suffix_id']) { $suffixes = array(); $suffixes = CRM_Core_PseudoConstant::individualSuffix(); $params['suffix'] = $suffixes[$params['suffix_id']]; } else { $params['suffix'] = $values['individual_suffix']; } return true; } //CRM-4575 if (isset($values['email_greeting'])) { if ($params['email_greeting_id']) { $emailGreetings = array(); $emailGreetingFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params), 'greeting_type' => 'email_greeting'); $emailGreetings = CRM_Core_PseudoConstant::greeting($emailGreetingFilter); $params['email_greeting'] = $emailGreetings[$params['email_greeting_id']]; } else { $params['email_greeting'] = $values['email_greeting']; } return true; } if (isset($values['postal_greeting'])) { if ($params['postal_greeting_id']) { $postalGreetings = array(); $postalGreetingFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params), 'greeting_type' => 'postal_greeting'); $postalGreetings = CRM_Core_PseudoConstant::greeting($postalGreetingFilter); $params['postal_greeting'] = $postalGreetings[$params['postal_greeting_id']]; } else { $params['postal_greeting'] = $values['postal_greeting']; } return true; } if (isset($values['addressee'])) { if ($params['addressee_id']) { $addressee = array(); $addresseeFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params), 'greeting_type' => 'addressee'); $addressee = CRM_Core_PseudoConstant::addressee($addresseeFilter); $params['addressee'] = $addressee[$params['addressee_id']]; } else { $params['addressee'] = $values['addressee']; } return true; } if (isset($values['gender'])) { if ($params['gender_id']) { $genders = array(); $genders = CRM_Core_PseudoConstant::gender(); $params['gender'] = $genders[$params['gender_id']]; } else { $params['gender'] = $values['gender']; } return true; } if (isset($values['preferred_communication_method'])) { $comm = array(); $preffComm = array(); $pcm = array(); $pcm = array_change_key_case(array_flip(CRM_Core_PseudoConstant::pcm()), CASE_LOWER); $preffComm = explode(',', $values['preferred_communication_method']); foreach ($preffComm as $v) { $v = strtolower(trim($v)); if (array_key_exists($v, $pcm)) { $comm[$pcm[$v]] = 1; } } $params['preferred_communication_method'] = $comm; return true; } // get the formatted location blocks into params - w/ 3.0 format, CRM-4605 if (CRM_Utils_Array::value('location_type_id', $values)) { _civicrm_add_formatted_location_blocks($values, $params); return true; } if (isset($values['note'])) { /* add a note field */ if (!isset($params['note'])) { $params['note'] = array(); } $noteBlock = count($params['note']) + 1; $params['note'][$noteBlock] = array(); if (!isset($fields['Note'])) { $fields['Note'] = CRM_Core_DAO_Note::fields(); } // get the current logged in civicrm user $session =& CRM_Core_Session::singleton(); $userID = $session->get('userID'); if ($userID) { $values['contact_id'] = $userID; } _civicrm_store_values($fields['Note'], $values, $params['note'][$noteBlock]); return true; } /* Check for custom field values */ if ($fields['custom'] == null) { $fields['custom'] =& CRM_Core_BAO_CustomField::getFields($values['contact_type']); } foreach ($values as $key => $value) { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) { /* check if it's a valid custom field id */ if (!array_key_exists($customFieldID, $fields['custom'])) { return civicrm_create_error('Invalid custom field ID'); } else { $params[$key] = $value; } } } }
/** * function to check if an error in Core( non-custom fields ) field * * @param String $errorMessage A string containing all the error-fields. * * @access public */ function isErrorInCoreData($params, &$errorMessage) { require_once 'CRM/Core/OptionGroup.php'; foreach ($params as $key => $value) { if ($value) { $session =& CRM_Core_Session::singleton(); $dateType = $session->get("dateTypes"); switch ($key) { case 'birth_date': if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) { if (!CRM_Utils_Rule::date($params[$key])) { self::addToErrorMsg(ts('Birth Date'), $errorMessage); } } else { self::addToErrorMsg(ts('Birth-Date'), $errorMessage); } break; case 'deceased_date': if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) { if (!CRM_Utils_Rule::date($params[$key])) { self::addToErrorMsg(ts('Deceased Date'), $errorMessage); } } else { self::addToErrorMsg(ts('Deceased Date'), $errorMessage); } break; case 'is_deceased': if (CRM_Utils_String::strtoboolstr($value) === false) { self::addToErrorMsg(ts('Is Deceased'), $errorMessage); } break; case 'gender': if (!self::checkGender($value)) { self::addToErrorMsg(ts('Gender'), $errorMessage); } break; case 'preferred_communication_method': $preffComm = array(); $preffComm = explode(',', $value); foreach ($preffComm as $v) { if (!self::in_value(trim($v), CRM_Core_PseudoConstant::pcm())) { self::addToErrorMsg(ts('Preferred Communication Method'), $errorMessage); } } break; case 'preferred_mail_format': if (!array_key_exists(strtolower($value), array_change_key_case(CRM_Core_SelectValues::pmf(), CASE_LOWER))) { self::addToErrorMsg(ts('Preferred Mail Format'), $errorMessage); } break; case 'individual_prefix': if (!self::in_value($value, CRM_Core_PseudoConstant::individualPrefix())) { self::addToErrorMsg(ts('Individual Prefix'), $errorMessage); } break; case 'individual_suffix': if (!self::in_value($value, CRM_Core_PseudoConstant::individualSuffix())) { self::addToErrorMsg(ts('Individual Suffix'), $errorMessage); } break; case 'state_province': if (!empty($value)) { foreach ($value as $stateValue) { if ($stateValue['state_province']) { if (self::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvinceAbbreviation()) || self::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvince())) { continue; } else { self::addToErrorMsg(ts('State / Province'), $errorMessage); } } } } break; case 'country': if (!empty($value)) { foreach ($value as $stateValue) { if ($stateValue['country']) { CRM_Core_PseudoConstant::populate($countryNames, 'CRM_Core_DAO_Country', true, 'name', 'is_active'); CRM_Core_PseudoConstant::populate($countryIsoCodes, 'CRM_Core_DAO_Country', true, 'iso_code'); $config =& CRM_Core_Config::singleton(); $limitCodes = $config->countryLimit(); //If no country is selected in //localization then take all countries if (empty($limitCodes)) { $limitCodes = $countryIsoCodes; } if (self::in_value($stateValue['country'], $limitCodes) || self::in_value($stateValue['country'], CRM_Core_PseudoConstant::country())) { continue; } else { if (self::in_value($stateValue['country'], $countryIsoCodes) || self::in_value($stateValue['country'], $countryNames)) { self::addToErrorMsg(ts('Country input value is in table but not "available": "This Country is valid but is NOT in the list of Available Countries currently configured for your site. This can be viewed and modifed from Global Settings >> Localization." '), $errorMessage); } else { self::addToErrorMsg(ts('Country input value not in country table: "The Country value appears to be invalid. It does not match any value in CiviCRM table of countries."'), $errorMessage); } } } } } break; case 'geo_code_1': if (!empty($value)) { foreach ($value as $codeValue) { if ($codeValue['geo_code_1']) { if (CRM_Utils_Rule::numeric($codeValue['geo_code_1'])) { continue; } else { self::addToErrorMsg(ts('Geo code 1'), $errorMessage); } } } } break; case 'geo_code_2': if (!empty($value)) { foreach ($value as $codeValue) { if ($codeValue['geo_code_2']) { if (CRM_Utils_Rule::numeric($codeValue['geo_code_2'])) { continue; } else { self::addToErrorMsg(ts('Geo code 2'), $errorMessage); } } } } break; //check for any error in email/postal greeting, addressee, //custom email/postal greeting, custom addressee, CRM-4575 //check for any error in email/postal greeting, addressee, //custom email/postal greeting, custom addressee, CRM-4575 case 'email_greeting': $emailGreetingFilter = array('contact_type' => $this->_contactType, 'greeting_type' => 'email_greeting'); if (!self::in_value($value, CRM_Core_PseudoConstant::greeting($emailGreetingFilter))) { self::addToErrorMsg(ts('Email Greeting must be one of the configured format options. Check Administer >> Option Lists >> Email Greetings for valid values'), $errorMessage); } break; case 'postal_greeting': $postalGreetingFilter = array('contact_type' => $this->_contactType, 'greeting_type' => 'postal_greeting'); if (!self::in_value($value, CRM_Core_PseudoConstant::greeting($postalGreetingFilter))) { self::addToErrorMsg(ts('Postal Greeting must be one of the configured format options. Check Administer >> Option Lists >> Postal Greetings for valid values'), $errorMessage); } break; case 'addressee': $addresseeFilter = array('contact_type' => $this->_contactType, 'greeting_type' => 'addressee'); if (!self::in_value($value, CRM_Core_PseudoConstant::greeting($addresseeFilter))) { self::addToErrorMsg(ts('Addressee must be one of the configured format options. Check Administer >> Option Lists >> Addressee for valid values'), $errorMessage); } break; case 'email_greeting_custom': if (array_key_exists('email_greeting', $params)) { $emailGreetingLabel = key(CRM_Core_OptionGroup::values('email_greeting', true, null, null, 'AND v.name = "Customized"')); if (CRM_Utils_Array::value('email_greeting', $params) != $emailGreetingLabel) { self::addToErrorMsg(ts('Email Greeting - Custom'), $errorMessage); } } break; case 'postal_greeting_custom': if (array_key_exists('postal_greeting', $params)) { $postalGreetingLabel = key(CRM_Core_OptionGroup::values('postal_greeting', true, null, null, 'AND v.name = "Customized"')); if (CRM_Utils_Array::value('postal_greeting', $params) != $postalGreetingLabel) { self::addToErrorMsg(ts('Postal Greeting - Custom'), $errorMessage); } } break; case 'addressee_custom': if (array_key_exists('addressee', $params)) { $addresseeLabel = key(CRM_Core_OptionGroup::values('addressee', true, null, null, 'AND v.name = "Customized"')); if (CRM_Utils_Array::value('addressee', $params) != $addresseeLabel) { self::addToErrorMsg(ts('Addressee - Custom'), $errorMessage); } } break; case 'home_URL': if (CRM_Utils_Rule::url($value) === false) { self::addToErrorMsg(ts('Website'), $errorMessage); } break; case 'do_not_email': case 'do_not_phone': case 'do_not_mail': case 'do_not_sms': case 'do_not_trade': if (CRM_Utils_Rule::boolean($value) == false) { $key = ucwords(str_replace("_", " ", $key)); self::addToErrorMsg($key, $errorMessage); } break; case 'email': if (is_array($value)) { foreach ($value as $values) { if (CRM_Utils_Array::value('email', $values) && !CRM_Utils_Rule::email($values['email'])) { self::addToErrorMsg($key, $errorMessage); break; } } } break; default: if (is_array($params[$key]) && isset($params[$key]["contact_type"])) { //check for any relationship data ,FIX ME self::isErrorInCoreData($params[$key], $errorMessage); } } } } }
/** * * Get the values for pseudoconstants for name->value and reverse. * * @param array $defaults (reference) the default values, some of which need to be resolved. * @param boolean $reverse true if we want to resolve the values in the reverse direction (value -> name) * * @return none * @access public * @static */ function resolveDefaults(&$defaults, $reverse = false) { // hack for birth_date if (CRM_Utils_Array::value('birth_date', $defaults)) { if (is_array($defaults['birth_date'])) { $defaults['birth_date'] = CRM_Utils_Date::format($defaults['birth_date'], '-'); } } if (CRM_Utils_Array::value('prefix', $defaults)) { CRM_Contact_BAO_Contact::lookupValue($defaults, 'prefix', CRM_Core_PseudoConstant::individualPrefix(), $reverse); } if (CRM_Utils_Array::value('suffix', $defaults)) { CRM_Contact_BAO_Contact::lookupValue($defaults, 'suffix', CRM_Core_PseudoConstant::individualSuffix(), $reverse); } if (CRM_Utils_Array::value('gender', $defaults)) { CRM_Contact_BAO_Contact::lookupValue($defaults, 'gender', CRM_Core_PseudoConstant::gender(), $reverse); } if (array_key_exists('location', $defaults)) { $locations =& $defaults['location']; foreach ($locations as $index => $location) { $location =& $locations[$index]; CRM_Contact_BAO_Contact::lookupValue($location, 'location_type', CRM_Core_PseudoConstant::locationType(), $reverse); // FIXME: lookupValue doesn't work for vcard_name $vcardNames =& CRM_Core_PseudoConstant::locationVcardName(); $location['vcard_name'] = $vcardNames[$location['location_type_id']]; if (array_key_exists('address', $location)) { if (!CRM_Contact_BAO_Contact::lookupValue($location['address'], 'state_province', CRM_Core_PseudoConstant::stateProvince(), $reverse) && $reverse) { CRM_Contact_BAO_Contact::lookupValue($location['address'], 'state_province', CRM_Core_PseudoConstant::stateProvinceAbbreviation(), $reverse); } if (!CRM_Contact_BAO_Contact::lookupValue($location['address'], 'country', CRM_Core_PseudoConstant::country(), $reverse) && $reverse) { CRM_Contact_BAO_Contact::lookupValue($location['address'], 'country', CRM_Core_PseudoConstant::countryIsoCode(), $reverse); } CRM_Contact_BAO_Contact::lookupValue($location['address'], 'county', CRM_Core_SelectValues::county(), $reverse); } if (array_key_exists('im', $location)) { $ims =& $location['im']; foreach ($ims as $innerIndex => $im) { $im =& $ims[$innerIndex]; CRM_Contact_BAO_Contact::lookupValue($im, 'provider', CRM_Core_PseudoConstant::IMProvider(), $reverse); unset($im); } } unset($location); } } }