コード例 #1
0
 public function updateGreeting()
 {
     $config = CRM_Core_Config::singleton();
     $contactType = CRM_Utils_Request::retrieve('ct', 'String', CRM_Core_DAO::$_nullArray, FALSE, NULL, 'REQUEST');
     if (!in_array($contactType, array('Individual', 'Household', 'Organization'))) {
         CRM_Core_Error::fatal(ts('Invalid Contact Type.'));
     }
     $greeting = CRM_Utils_Request::retrieve('gt', 'String', CRM_Core_DAO::$_nullArray, FALSE, NULL, 'REQUEST');
     if (!in_array($greeting, array('email_greeting', 'postal_greeting', 'addressee'))) {
         CRM_Core_Error::fatal(ts('Invalid Greeting Type.'));
     }
     if (in_array($greeting, array('email_greeting', 'postal_greeting')) && $contactType == 'Organization') {
         CRM_Core_Error::fatal(ts('You cannot use %1 for contact type %2.', array(1 => $greeting, 2 => $contactType)));
     }
     $valueID = $id = CRM_Utils_Request::retrieve('id', 'Positive', CRM_Core_DAO::$_nullArray, FALSE, NULL, 'REQUEST');
     // if valueID is not passed use default value
     if (!$valueID) {
         require_once 'CRM/Core/OptionGroup.php';
         $contactTypeFilters = array(1 => 'Individual', 2 => 'Household', 3 => 'Organization');
         $filter = CRM_Utils_Array::key($contactType, $contactTypeFilters);
         $defaulValueID = CRM_Core_OptionGroup::values($greeting, NULL, NULL, NULL, " AND is_default = 1 AND ( filter = {$filter} OR filter = 0 )", "value");
         $valueID = array_pop($defaulValueID);
     }
     $filter = array('contact_type' => $contactType, 'greeting_type' => $greeting);
     $allGreetings = CRM_Core_PseudoConstant::greeting($filter);
     $originalGreetingString = $greetingString = CRM_Utils_Array::value($valueID, $allGreetings);
     if (!$greetingString) {
         CRM_Core_Error::fatal(ts('Incorrect greeting value id %1.', array(1 => $valueID)));
     }
     // build return properties based on tokens
     require_once 'CRM/Utils/Token.php';
     $greetingTokens = CRM_Utils_Token::getTokens($greetingString);
     $tokens = CRM_Utils_Array::value('contact', $greetingTokens);
     $greetingsReturnProperties = array();
     if (is_array($tokens)) {
         $greetingsReturnProperties = array_fill_keys(array_values($tokens), 1);
     }
     //process all contacts only when force pass.
     $force = CRM_Utils_Request::retrieve('force', 'String', CRM_Core_DAO::$_nullArray, FALSE, NULL, 'REQUEST');
     $processAll = $processOnlyIdSet = FALSE;
     if (in_array($force, array(1, 'true'))) {
         $processAll = TRUE;
     } elseif ($force == 2) {
         $processOnlyIdSet = TRUE;
     }
     //FIXME : apiQuery should handle these clause.
     $filterContactFldIds = $filterIds = array();
     if (!$processAll) {
         $idFldName = $displayFldName = NULL;
         if ($greeting == 'email_greeting' || $greeting == 'postal_greeting' || $greeting == 'addressee') {
             $idFldName = $greeting . '_id';
             $displayFldName = $greeting . '_display';
         }
         if ($idFldName) {
             $sql = "\nSELECT DISTINCT id, {$idFldName}\n  FROM civicrm_contact\n WHERE contact_type = %1\n   AND ( {$idFldName} IS NULL OR\n         ( {$idFldName} IS NOT NULL AND {$displayFldName} IS NULL ) )\n   ";
             $dao = CRM_Core_DAO::executeQuery($sql, array(1 => array($contactType, 'String')));
             while ($dao->fetch()) {
                 $filterContactFldIds[$dao->id] = $dao->{$idFldName};
                 if (!CRM_Utils_System::isNull($dao->{$idFldName})) {
                     $filterIds[$dao->id] = $dao->{$idFldName};
                 }
             }
         }
         if (empty($filterContactFldIds)) {
             $filterContactFldIds[] = 0;
         }
     }
     if (empty($filterContactFldIds)) {
         return;
     }
     // retrieve only required contact information
     require_once 'CRM/Utils/Token.php';
     $extraParams[] = array('contact_type', '=', $contactType, 0, 0);
     // we do token replacement in the replaceGreetingTokens hook
     list($greetingDetails) = CRM_Utils_Token::getTokenDetails(array_keys($filterContactFldIds), $greetingsReturnProperties, FALSE, FALSE, $extraParams);
     // perform token replacement and build update SQL
     $contactIds = array();
     $cacheFieldQuery = "UPDATE civicrm_contact SET {$greeting}_display = CASE id ";
     foreach ($greetingDetails as $contactID => $contactDetails) {
         if (!$processAll && !array_key_exists($contactID, $filterContactFldIds)) {
             continue;
         }
         if ($processOnlyIdSet) {
             if (!array_key_exists($contactID, $filterIds)) {
                 continue;
             }
             if ($id) {
                 $greetingString = $originalGreetingString;
                 $contactIds[] = $contactID;
             } else {
                 if ($greetingBuffer = CRM_Utils_Array::value($filterContactFldIds[$contactID], $allGreetings)) {
                     $greetingString = $greetingBuffer;
                 }
             }
             $allContactIds[] = $contactID;
         } else {
             $greetingString = $originalGreetingString;
             if ($greetingBuffer = CRM_Utils_Array::value($filterContactFldIds[$contactID], $allGreetings)) {
                 $greetingString = $greetingBuffer;
             } else {
                 $contactIds[] = $contactID;
             }
         }
         CRM_Contact_BAO_Contact_Utils::processGreetingTemplate($greetingString, $contactDetails, $contactID, 'CRM_UpdateGreeting');
         $greetingString = CRM_Core_DAO::escapeString($greetingString);
         $cacheFieldQuery .= " WHEN {$contactID} THEN '{$greetingString}' ";
         $allContactIds[] = $contactID;
     }
     if (!empty($allContactIds)) {
         $cacheFieldQuery .= " ELSE {$greeting}_display\n                              END;";
         if (!empty($contactIds)) {
             // need to update greeting _id field.
             $queryString = "\nUPDATE civicrm_contact\n   SET {$greeting}_id = {$valueID}\n WHERE id IN (" . implode(',', $contactIds) . ")";
             CRM_Core_DAO::executeQuery($queryString);
         }
         // now update cache field
         CRM_Core_DAO::executeQuery($cacheFieldQuery);
     }
 }
コード例 #2
0
 /**
  * Get all types of Greetings.
  *
  * The static array of greeting is returned
  *
  * @access public
  * @static
  *
  * @param $filter - get All Email Greetings - default is to get only active ones.
  *
  * @return array - array reference of all greetings.
  *
  */
 public static function greeting($filter, $columnName = 'label')
 {
     $index = $filter['greeting_type'] . '_' . $columnName;
     // also add contactType to the array
     $contactType = CRM_Utils_Array::value('contact_type', $filter);
     if ($contactType) {
         $index .= '_' . $contactType;
     }
     if (NULL === self::$greeting) {
         self::$greeting = array();
     }
     if (!CRM_Utils_Array::value($index, self::$greeting)) {
         $filterCondition = NULL;
         if ($contactType) {
             $filterVal = 'v.filter =';
             switch ($contactType) {
                 case 'Individual':
                     $filterVal .= "1";
                     break;
                 case 'Household':
                     $filterVal .= "2";
                     break;
                 case 'Organization':
                     $filterVal .= "3";
                     break;
             }
             $filterCondition .= "AND (v.filter = 0 OR {$filterVal}) ";
         }
         self::$greeting[$index] = CRM_Core_OptionGroup::values($filter['greeting_type'], NULL, NULL, NULL, $filterCondition, $columnName);
     }
     return self::$greeting[$index];
 }
コード例 #3
0
ファイル: UFGroup.php プロジェクト: rollox/civicrm-core
 /**
  * Add profile field to a form.
  *
  * @param CRM_Core_Form $form
  * @param array $field
  *   Properties.
  * @param int $mode
  *   Profile mode.
  * @param int $contactId
  * @param bool $online
  * @param string $usedFor
  *   For building up prefixed fieldname for special cases (e.g. onBehalf, Honor).
  * @param int $rowNumber
  * @param string $prefix
  *
  * @return null
  */
 public static function buildProfile(&$form, &$field, $mode, $contactId = NULL, $online = FALSE, $usedFor = NULL, $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 NULL;
     }
     if ($usedFor == 'onbehalf') {
         $name = "onbehalf[{$fieldName}]";
     } elseif ($usedFor == 'honor') {
         $name = "honor[{$fieldName}]";
     } elseif ($contactId && !$online) {
         $name = "field[{$contactId}][{$fieldName}]";
     } elseif ($rowNumber) {
         $name = "field[{$rowNumber}][{$fieldName}]";
     } elseif (!empty($prefix)) {
         $name = $prefix . "[{$fieldName}]";
     } else {
         $name = $fieldName;
     }
     $selectAttributes = array('class' => 'crm-select2', 'placeholder' => TRUE);
     if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) {
         $deleteExtra = json_encode(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 = "' . htmlspecialchars("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')), ts('more'), FALSE, 'contact.profileimage.delete', 'Contact', $form->get('id'));
         $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->addChainSelect($name, array('label' => $title, 'required' => $required));
         $config = CRM_Core_Config::singleton();
         if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactStateProvince) {
             $defaultValues[$name] = $config->defaultContactStateProvince;
             $form->setDefaults($defaultValues);
         }
     } elseif (substr($fieldName, 0, 7) === 'country') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required, $selectAttributes);
         $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->addChainSelect($name, array('label' => $title, 'required' => $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 ($usedFor) {
                 if (substr($name, -1) == ']') {
                     $providerName = substr($name, 0, -1) . '-provider_id]';
                 }
                 $form->add('select', $providerName, NULL, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required);
             } else {
                 $form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $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' => 'activityDate'));
     } elseif (CRM_Utils_Array::value('name', $field) == 'membership_type') {
         list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo();
         $sel =& $form->addElement('hierselect', $name, $title);
         $select = array('' => ts('- select -'));
         if (count($orgInfo) == 1 && $field['is_required']) {
             // we only have one org - so we should default to it. Not sure about defaulting to first type
             // as it could be missed - so adding a select
             // however, possibly that is more similar to the membership form
             if (count($types[1]) > 1) {
                 $types[1] = $select + $types[1];
             }
         } else {
             $orgInfo = $select + $orgInfo;
         }
         $sel->setOptions(array($orgInfo, $types));
     } elseif (CRM_Utils_Array::value('name', $field) == 'membership_status') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), $required);
     } elseif (in_array($fieldName, array('gender_id', 'communication_style_id'))) {
         $options = array();
         $pseudoValues = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', $fieldName);
         foreach ($pseudoValues as $key => $var) {
             $options[$key] = $form->createElement('radio', NULL, ts($title), $var, $key);
         }
         $group = $form->addGroup($options, $name, $title);
         if ($required) {
             $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required');
         } else {
             $group->setAttribute('allowClear', TRUE);
         }
     } elseif ($fieldName === 'prefix_id' || $fieldName === 'suffix_id') {
         $form->addSelect($name, array('label' => $title, 'entity' => 'contact', 'field' => $fieldName, 'class' => 'six', 'placeholder' => ''), $required);
     } elseif ($fieldName === 'contact_sub_type') {
         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
         if ($usedFor == 'onbehalf') {
             $profileType = 'Organization';
         } elseif ($usedFor == 'honor') {
             $profileType = CRM_Core_BAO_UFField::getProfileType($form->_params['honoree_profile_id']);
         } else {
             $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL;
             if ($profileType == 'Contact') {
                 $profileType = 'Individual';
             }
         }
         $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;
         }
         $form->add('select', $name, $title, $subtypeList, $required, array('class' => 'crm-select2', 'multiple' => 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::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
         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_Contact_BAO_Contact::buildOptions('preferred_language'));
     } 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->add('text', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), $required);
         $form->addRule($name, ts('Enter a valid web address beginning with \'http://\' or \'https://\'.'), 'url');
     } elseif (substr($fieldName, -4) == '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') {
         $form->addEntityRef("soft_credit_contact_id[{$rowNumber}]", ts('Soft Credit To'), array('create' => TRUE));
         $form->addMoney("soft_credit_amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE);
     } 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 == 'financial_type') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType(), $required);
     } elseif ($fieldName == 'contribution_status_id') {
         $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus();
         $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
         foreach (array('In Progress', 'Overdue', 'Refunded') as $suppress) {
             unset($contributionStatuses[CRM_Utils_Array::key($suppress, $statusName)]);
         }
         $form->add('select', $name, $title, array('' => ts('- select -')) + $contributionStatuses, $required);
     } elseif ($fieldName == 'soft_credit_type') {
         $name = "soft_credit_type[{$rowNumber}]";
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_OptionGroup::values("soft_credit_type"));
         //CRM-15350: choose SCT field default value as 'Gift' for membership use
         //else (for contribution), use configured SCT default value
         $SCTDefaultValue = CRM_Core_OptionGroup::getDefaultValue("soft_credit_type");
         if ($field['field_type'] == 'Membership') {
             $SCTDefaultValue = CRM_Core_OptionGroup::getValue('soft_credit_type', 'Gift', 'name');
         }
         $form->addElement('hidden', 'sct_default_id', $SCTDefaultValue, array('id' => 'sct_default_id'));
     } 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 (!empty($field['is_multiple'])) {
             $form->addCheckBox($name, $title, CRM_Event_PseudoConstant::participantRole(), NULL, NULL, NULL, NULL, '&nbsp', TRUE);
         } else {
             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), $required);
         }
     } elseif ($fieldName == 'world_region') {
         $form->add('select', $name, $title, CRM_Core_PseudoConstant::worldRegion(), $required, $selectAttributes);
     } elseif ($fieldName == 'signature_html') {
         $form->add('wysiwyg', $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));
             $form->add('select', $name, $title, array('' => ts('- select -')) + $campaigns, $required, 'class="crm-select2 big"');
         }
     } elseif ($fieldName == 'activity_details') {
         $form->add('wysiwyg', $fieldName, $title, array('rows' => 4, 'cols' => 60), $required);
     } elseif ($fieldName == 'activity_duration') {
         $form->add('text', $name, $title, $attributes, $required);
         $form->addRule($name, ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger');
     } else {
         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 ($usedFor) {
             $form->addElement('hidden', $usedFor . '[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);
         }
     }
 }
コード例 #4
0
ファイル: Contact.php プロジェクト: bhirsch/voipdev
 /**
  * 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);
                     }
             }
         }
     }
 }
コード例 #5
0
 function restWhere(&$values)
 {
     $name = CRM_Utils_Array::value(0, $values);
     $op = CRM_Utils_Array::value(1, $values);
     $value = CRM_Utils_Array::value(2, $values);
     $grouping = CRM_Utils_Array::value(3, $values);
     $wildcard = CRM_Utils_Array::value(4, $values);
     if (isset($grouping) && empty($this->_where[$grouping])) {
         $this->_where[$grouping] = array();
     }
     $multipleFields = array('url');
     //check if the location type exits for fields
     $lType = '';
     $locType = explode('-', $name);
     if (!in_array($locType[0], $multipleFields)) {
         //add phone type if exists
         if (isset($locType[2]) && $locType[2]) {
             $locType[2] = CRM_Core_DAO::escapeString($locType[2]);
         }
     }
     $field = CRM_Utils_Array::value($name, $this->_fields);
     if (!$field) {
         $field = CRM_Utils_Array::value($locType[0], $this->_fields);
         if (!$field) {
             return;
         }
     }
     $setTables = TRUE;
     $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
     $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     if (substr($name, 0, 14) === 'state_province') {
         if (isset($locType[1]) && is_numeric($locType[1])) {
             $setTables = FALSE;
             $aName = "{$locationType[$locType[1]]}-address";
             $where = "`{$aName}`.state_province_id";
         } else {
             $where = "civicrm_address.state_province_id";
         }
         $states = CRM_Core_PseudoConstant::stateProvince();
         if (is_numeric($value)) {
             $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
             $value = $states[(int) $value];
         } else {
             $intVal = CRM_Utils_Array::key($value, $states);
             $this->_where[$grouping][] = self::buildClause($where, $op, $intVal, 'Positive');
         }
         if (!$lType) {
             $this->_qill[$grouping][] = ts('State') . " {$op} '{$value}'";
         } else {
             $this->_qill[$grouping][] = ts('State') . " ({$lType}) {$op} '{$value}'";
         }
     } elseif (!empty($field['pseudoconstant'])) {
         $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', $field['name']), $field, $field['title'], 'String', TRUE);
         if ($name == 'gender_id') {
             self::$_openedPanes[ts('Demographics')] = TRUE;
         }
     } elseif (substr($name, 0, 7) === 'country') {
         if (isset($locType[1]) && is_numeric($locType[1])) {
             $setTables = FALSE;
             $aName = "{$locationType[$locType[1]]}-address";
             $where = "`{$aName}`.country_id";
         } else {
             $where = "civicrm_address.country_id";
         }
         $countries = CRM_Core_PseudoConstant::country();
         if (is_numeric($value)) {
             $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
             $value = $countries[(int) $value];
         } else {
             $intVal = CRM_Utils_Array::key($value, $countries);
             $this->_where[$grouping][] = self::buildClause($where, $op, $intVal, 'Positive');
         }
         if (!$lType) {
             $this->_qill[$grouping][] = ts('Country') . " {$op} '{$value}'";
         } else {
             $this->_qill[$grouping][] = ts('Country') . " ({$lType}) {$op} '{$value}'";
         }
     } elseif (substr($name, 0, 6) === 'county') {
         if (isset($locType[1]) && is_numeric($locType[1])) {
             $setTables = FALSE;
             $aName = "{$locationType[$locType[1]]}-address";
             $where = "`{$aName}`.county_id";
         } else {
             $where = "civicrm_address.county_id";
         }
         $counties = CRM_Core_PseudoConstant::county();
         if (is_numeric($value)) {
             $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
             $value = $counties[(int) $value];
         } else {
             $intVal = CRM_Utils_Array::key($value, $counties);
             $this->_where[$grouping][] = self::buildClause($where, $op, $intVal, 'Positive');
         }
         if (!$lType) {
             $this->_qill[$grouping][] = ts('County') . " {$op} '{$value}'";
         } else {
             $this->_qill[$grouping][] = ts('County') . " ({$lType}) {$op} '{$value}'";
         }
     } elseif ($name === 'world_region') {
         $field['where'] = 'civicrm_worldregion.id';
         $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::worldRegion(), $field, ts('World Region'));
     } elseif ($name === 'birth_date') {
         $date = CRM_Utils_Date::processDate($value);
         $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date);
         if ($date) {
             $date = CRM_Utils_Date::customFormat($date);
             $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\"";
         } else {
             $this->_qill[$grouping][] = "{$field['title']} {$op}";
         }
         self::$_openedPanes[ts('Demographics')] = TRUE;
     } elseif ($name === 'deceased_date') {
         $date = CRM_Utils_Date::processDate($value);
         $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date);
         if ($date) {
             $date = CRM_Utils_Date::customFormat($date);
             $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\"";
         } else {
             $this->_qill[$grouping][] = "{$field['title']} {$op}";
         }
         self::$_openedPanes[ts('Demographics')] = TRUE;
     } elseif ($name === 'is_deceased') {
         $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $value);
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
         self::$_openedPanes[ts('Demographics')] = TRUE;
     } elseif ($name === 'contact_id') {
         if (is_int($value)) {
             $this->_where[$grouping][] = self::buildClause($field['where'], $op, $value);
             $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}";
         }
     } elseif ($name === 'name') {
         $value = $strtolower(CRM_Core_DAO::escapeString($value));
         if ($wildcard) {
             $value = "%{$value}%";
             $op = 'LIKE';
         }
         $wc = self::caseImportant($op) ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}'");
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } elseif ($name === 'current_employer') {
         $value = $strtolower(CRM_Core_DAO::escapeString($value));
         if ($wildcard) {
             $value = "%{$value}%";
             $op = 'LIKE';
         }
         $wc = self::caseImportant($op) ? "LOWER(contact_a.organization_name)" : "contact_a.organization_name";
         $ceWhereClause = self::buildClause($wc, $op, $value);
         $ceWhereClause .= " AND contact_a.contact_type = 'Individual'";
         $this->_where[$grouping][] = $ceWhereClause;
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } elseif ($name === 'email_greeting') {
         $filterCondition = array('greeting_type' => 'email_greeting');
         $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Email Greeting'));
     } elseif ($name === 'postal_greeting') {
         $filterCondition = array('greeting_type' => 'postal_greeting');
         $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Postal Greeting'));
     } elseif ($name === 'addressee') {
         $filterCondition = array('greeting_type' => 'addressee');
         $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Addressee'));
     } elseif (substr($name, 0, 4) === 'url-') {
         $tName = 'civicrm_website';
         $this->_whereTables[$tName] = $this->_tables[$tName] = "\nLEFT JOIN civicrm_website ON ( civicrm_website.contact_id = contact_a.id )";
         $value = $strtolower(CRM_Core_DAO::escapeString($value));
         if ($wildcard) {
             $value = "%{$value}%";
             $op = 'LIKE';
         }
         $wc = 'civicrm_website.url';
         $this->_where[$grouping][] = $d = self::buildClause($wc, $op, $value);
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } elseif ($name === 'contact_is_deleted') {
         $this->_where[$grouping][] = self::buildClause("contact_a.is_deleted", $op, $value);
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } else {
         // sometime the value is an array, need to investigate and fix
         if (is_array($value)) {
             CRM_Core_Error::fatal();
         }
         if (!empty($field['where'])) {
             if ($op != 'IN') {
                 $value = $strtolower($value);
             }
             if ($wildcard) {
                 $value = "%{$value}%";
                 $op = 'LIKE';
             }
             if (isset($locType[1]) && is_numeric($locType[1])) {
                 $setTables = FALSE;
                 //get the location name
                 list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
                 $where = "`{$tName}`.{$fldName}";
                 $this->_where[$grouping][] = self::buildClause("LOWER({$where})", $op, $value);
                 $this->_whereTables[$tName] = $this->_tables[$tName];
                 $this->_qill[$grouping][] = "{$field['title']} {$op} '{$value}'";
             } else {
                 list($tableName, $fieldName) = explode('.', $field['where'], 2);
                 if ($tableName == 'civicrm_contact') {
                     $fieldName = "LOWER(contact_a.{$fieldName})";
                 } else {
                     if ($op != 'IN' && !is_numeric($value)) {
                         $fieldName = "LOWER({$field['where']})";
                     } else {
                         $fieldName = "{$field['where']}";
                     }
                 }
                 $type = NULL;
                 if (!empty($field['type'])) {
                     $type = CRM_Utils_Type::typeToString($field['type']);
                 }
                 $this->_where[$grouping][] = self::buildClause($fieldName, $op, $value, $type);
                 $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}";
             }
         }
     }
     if ($setTables && isset($field['where'])) {
         list($tableName, $fieldName) = explode('.', $field['where'], 2);
         if (isset($tableName)) {
             $this->_tables[$tableName] = 1;
             $this->_whereTables[$tableName] = 1;
         }
     }
 }
コード例 #6
0
ファイル: Event.php プロジェクト: prashantgajare/civicrm-core
 /**
  * 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
  *
  * @param array $profileFields
  *
  * @return void
  * @access public
  * @static
  */
 static function displayProfile(&$params, $gid, &$groupTitle, &$values, &$profileFields = array())
 {
     if ($gid) {
         $config = CRM_Core_Config::singleton();
         $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);
         }
         foreach ($fields as $v) {
             if (!empty($v['groupTitle'])) {
                 $groupTitle['groupTitle'] = $v['groupTitle'];
                 break;
             }
         }
         $customVal = '';
         $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
         //start of code to set the default values
         foreach ($fields as $name => $field) {
             $skip = FALSE;
             // skip fields that should not be displayed separately
             if ($field['skipDisplay']) {
                 continue;
             }
             $index = $field['title'];
             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] = '';
                 }
             } elseif ('date' == substr($name, -4)) {
                 $values[$index] = CRM_Utils_Date::customFormat(CRM_Utils_Date::processDate($params[$name]), $config->dateformatFull);
             } elseif ('country' == substr($name, 0, 7)) {
                 if ($params[$name]) {
                     $values[$index] = CRM_Core_PseudoConstant::country($params[$name]);
                 } else {
                     $values[$index] = '';
                 }
             } elseif ('county' == substr($name, 0, 6)) {
                 if ($params[$name]) {
                     $values[$index] = CRM_Core_PseudoConstant::county($params[$name]);
                 } else {
                     $values[$index] = '';
                 }
             } elseif (in_array(substr($name, 0, -3), array('gender', 'prefix', 'suffix', 'communication_style'))) {
                 $values[$index] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', $name, $params[$name]);
             } elseif (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]];
             } elseif ($name === 'preferred_communication_method') {
                 $communicationFields = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
                 $compref = array();
                 $pref = $params[$name];
                 if (is_array($pref)) {
                     foreach ($pref as $k => $v) {
                         if ($v) {
                             $compref[] = $communicationFields[$k];
                         }
                     }
                 }
                 $values[$index] = implode(',', $compref);
             } elseif ($name == 'contact_sub_type') {
                 $values[$index] = implode(', ', $params[$name]);
             } elseif ($name == 'group') {
                 $groups = CRM_Contact_BAO_GroupContact::getGroupList();
                 $title = array();
                 foreach ($params[$name] as $gId => $dontCare) {
                     if ($dontCare) {
                         $title[] = $groups[$gId];
                     }
                 }
                 $values[$index] = implode(', ', $title);
             } elseif ($name == 'tag') {
                 $entityTags = $params[$name];
                 $allTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
                 $title = array();
                 if (is_array($entityTags)) {
                     foreach ($entityTags as $tagId => $dontCare) {
                         $title[] = $allTags[$tagId];
                     }
                 }
                 $values[$index] = implode(', ', $title);
             } elseif ('participant_role_id' == $name or 'participant_role' == $name) {
                 $roles = CRM_Event_PseudoConstant::participantRole();
                 $values[$index] = $roles[$params[$name]];
             } elseif ('participant_status_id' == $name or 'participant_status' == $name) {
                 $status = CRM_Event_PseudoConstant::participantStatus();
                 $values[$index] = $status[$params[$name]];
             } elseif (substr($name, -11) == 'campaign_id') {
                 $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($params[$name]);
                 $values[$index] = CRM_Utils_Array::value($params[$name], $campaigns);
             } elseif (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];
                 } elseif ($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];
                     }
                 } elseif ($fieldName == 'phone') {
                     $phoneExtField = str_replace('phone', 'phone_ext', $detailName);
                     if (isset($params[$phoneExtField])) {
                         $values[$index] = $params[$detailName] . " (" . $params[$phoneExtField] . ")";
                     } 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 {
                     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);
                         $dao->fetch();
                         $htmlType = $dao->html_type;
                         if ($htmlType == 'File') {
                             $values[$index] = $params[$index];
                         } else {
                             if ($dao->data_type == 'Int' || $dao->data_type == 'Boolean') {
                                 $v = $params[$name];
                                 if (!CRM_Utils_System::isNull($v)) {
                                     $customVal = (int) $v;
                                 }
                             } elseif ($dao->data_type == 'Float') {
                                 $customVal = (double) $params[$name];
                             } elseif ($dao->data_type == 'Date') {
                                 //@todo note the currently we are using default date time formatting. Since you can select/set
                                 // different date and time format specific to custom field we should consider fixing this
                                 // sometime in the future
                                 $customVal = $displayValue = CRM_Utils_Date::customFormat(CRM_Utils_Date::processDate($params[$name]), $config->dateformatFull);
                                 if (!empty($params[$name . '_time'])) {
                                     $customVal = $displayValue = CRM_Utils_Date::customFormat(CRM_Utils_Date::processDate($params[$name], $params[$name . '_time']), $config->dateformatDatetime);
                                 }
                                 $skip = TRUE;
                             } else {
                                 $customVal = $params[$name];
                             }
                             //take the custom field options
                             $returnProperties = array($name => 1);
                             $query = new CRM_Contact_BAO_Query($params, $returnProperties, $fields);
                             $options =& $query->_options;
                             if (!$skip) {
                                 $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;
                             }
                         }
                     } elseif ($name == 'home_URL' && !empty($params[$name])) {
                         $url = CRM_Utils_System::fixURL($params[$name]);
                         $values[$index] = "<a href=\"{$url}\">{$params[$name]}</a>";
                     } elseif (in_array($name, array('birth_date', 'deceased_date', 'participant_register_date'))) {
                         $values[$index] = CRM_Utils_Date::customFormat(CRM_Utils_Date::format($params[$name]));
                     } else {
                         $values[$index] = $params[$name];
                     }
                 }
             }
             $profileFields[$name] = $field;
         }
     }
 }
コード例 #7
0
 function restWhere(&$values)
 {
     list($name, $op, $value, $grouping, $wildcard) = $values;
     if (!CRM_Utils_Array::value($grouping, $this->_where)) {
         $this->_where[$grouping] = array();
     }
     $multipleFields = array('url');
     //check if the location type exits for fields
     $lType = '';
     $locType = array();
     $locType = explode('-', $name);
     if (!in_array($locType[0], $multipleFields)) {
         //add phone type if exists
         if (isset($locType[2]) && $locType[2]) {
             $locType[2] = CRM_Core_DAO::escapeString($locType[2]);
         }
     }
     $field = CRM_Utils_Array::value($name, $this->_fields);
     if (!$field) {
         $field = CRM_Utils_Array::value($locType[0], $this->_fields);
         if (!$field) {
             return;
         }
     }
     $setTables = TRUE;
     $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
     if (substr($name, 0, 14) === 'state_province') {
         if (isset($locType[1]) && is_numeric($locType[1])) {
             $setTables = FALSE;
             //get the location name
             $locationType = CRM_Core_PseudoConstant::locationType();
             list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
             $this->_whereTables[$tName] = $this->_tables[$tName];
             $where = "`{$tName}`.{$fldName}";
         } else {
             $where = $field['where'];
         }
         $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
         if (is_numeric($value)) {
             $where = str_replace('.name', '.id', $where);
             $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
             $states = CRM_Core_PseudoConstant::stateProvince();
             $value = $states[(int) $value];
         } else {
             $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
             $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         }
         if (!$lType) {
             $this->_qill[$grouping][] = ts('State') . " {$op} '{$value}'";
         } else {
             $this->_qill[$grouping][] = ts('State') . " ({$lType}) {$op} '{$value}'";
         }
     } elseif (substr($name, 0, 7) === 'country') {
         if (isset($locType[1]) && is_numeric($locType[1])) {
             $setTables = FALSE;
             //get the location name
             $locationType = CRM_Core_PseudoConstant::locationType();
             list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
             $this->_whereTables[$tName] = $this->_tables[$tName];
             $where = "`{$tName}`.{$fldName}";
         } else {
             $where = $field['where'];
         }
         if (is_numeric($value)) {
             $where = str_replace('.name', '.id', $where);
             $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
             $countries = CRM_Core_PseudoConstant::country();
             $value = $countries[(int) $value];
         } else {
             $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
             $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         }
         if (!$lType) {
             $this->_qill[$grouping][] = ts('Country') . " {$op} '{$value}'";
         } else {
             $this->_qill[$grouping][] = ts('Country') . " ({$lType}) {$op} '{$value}'";
         }
     } elseif (substr($name, 0, 6) === 'county') {
         if (isset($locType[1]) && is_numeric($locType[1])) {
             $setTables = FALSE;
             //get the location name
             $locationType = CRM_Core_PseudoConstant::locationType();
             list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
             $this->_whereTables[$tName] = $this->_tables[$tName];
             $where = "`{$tName}`.{$fldName}";
         } else {
             $where = $field['where'];
         }
         if (is_numeric($value)) {
             $where = str_replace('.name', '.id', $where);
             $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
             $counties = CRM_Core_PseudoConstant::county();
             $value = $counties[(int) $value];
         } else {
             $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
             $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         }
         if (!$lType) {
             $this->_qill[$grouping][] = ts('County') . " {$op} '{$value}'";
         } else {
             $this->_qill[$grouping][] = ts('County') . " ({$lType}) {$op} '{$value}'";
         }
     } elseif ($name === 'world_region') {
         $worldRegions = CRM_Core_PseudoConstant::worldRegion();
         if (is_numeric($value)) {
             $value = $worldRegions[(int) $value];
         }
         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         $this->_qill[$grouping][] = ts('World Region') . " {$op} '{$value}'";
     } elseif ($name === 'individual_prefix') {
         $individualPrefixs = CRM_Core_PseudoConstant::individualPrefix();
         if (is_numeric($value)) {
             $value = $individualPrefixs[(int) $value];
         }
         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         $this->_qill[$grouping][] = ts('Individual Prefix') . " {$op} '{$value}'";
     } elseif ($name === 'individual_suffix') {
         $individualSuffixs = CRM_Core_PseudoConstant::individualsuffix();
         if (is_numeric($value)) {
             $value = $individualSuffixs[(int) $value];
         }
         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         $this->_qill[$grouping][] = ts('Individual Suffix') . " {$op} '{$value}'";
     } elseif ($name === 'gender') {
         $genders = CRM_Core_PseudoConstant::gender();
         if (is_numeric($value)) {
             $value = $genders[(int) $value];
         }
         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         $this->_qill[$grouping][] = ts('Gender') . " {$op} '{$value}'";
         self::$_openedPanes['Demographics'] = TRUE;
     } elseif ($name === 'birth_date') {
         $date = CRM_Utils_Date::processDate($value);
         $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date);
         if ($date) {
             $date = CRM_Utils_Date::customFormat($date);
             $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\"";
         } else {
             $this->_qill[$grouping][] = "{$field['title']} {$op}";
         }
         self::$_openedPanes['Demographics'] = TRUE;
     } elseif ($name === 'deceased_date') {
         $date = CRM_Utils_Date::processDate($value);
         $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date);
         if ($date) {
             $date = CRM_Utils_Date::customFormat($date);
             $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\"";
         } else {
             $this->_qill[$grouping][] = "{$field['title']} {$op}";
         }
         self::$_openedPanes['Demographics'] = TRUE;
     } elseif ($name === 'is_deceased') {
         $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $value);
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
         self::$_openedPanes['Demographics'] = TRUE;
     } elseif ($name === 'contact_id') {
         if (is_int($value)) {
             $this->_where[$grouping][] = self::buildClause($field['where'], $op, $value);
             $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}";
         }
     } elseif ($name === 'name') {
         $value = $strtolower(CRM_Core_DAO::escapeString($value));
         if ($wildcard) {
             $value = "%{$value}%";
             $op = 'LIKE';
         }
         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}'");
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } elseif ($name === 'current_employer') {
         $value = $strtolower(CRM_Core_DAO::escapeString($value));
         if ($wildcard) {
             $value = "%{$value}%";
             $op = 'LIKE';
         }
         $wc = $op != 'LIKE' ? "LOWER(contact_a.organization_name)" : "contact_a.organization_name";
         $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}' AND contact_a.contact_type ='Individual'");
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } elseif ($name === 'email_greeting') {
         $filterCondition = array('greeting_type' => 'email_greeting');
         $emailGreetings = CRM_Core_PseudoConstant::greeting($filterCondition);
         if (is_numeric($value)) {
             $value = $emailGreetings[(int) $value];
         }
         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         $this->_qill[$grouping][] = ts('Email Greeting') . " {$op} '{$value}'";
     } elseif ($name === 'postal_greeting') {
         $filterCondition = array('greeting_type' => 'postal_greeting');
         $postalGreetings = CRM_Core_PseudoConstant::greeting($filterCondition);
         if (is_numeric($value)) {
             $value = $postalGreetings[(int) $value];
         }
         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         $this->_qill[$grouping][] = ts('Postal Greeting') . " {$op} '{$value}'";
     } elseif ($name === 'addressee') {
         $filterCondition = array('greeting_type' => 'addressee');
         $addressee = CRM_Core_PseudoConstant::greeting($filterCondition);
         if (is_numeric($value)) {
             $value = $addressee[(int) $value];
         }
         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         $this->_qill[$grouping][] = ts('Addressee') . " {$op} '{$value}'";
     } elseif (substr($name, 0, 4) === 'url-') {
         $tName = 'civicrm_website';
         $this->_whereTables[$tName] = $this->_tables[$tName] = "\nLEFT JOIN civicrm_website ON ( civicrm_website.contact_id = contact_a.id )";
         $value = $strtolower(CRM_Core_DAO::escapeString($value));
         if ($wildcard) {
             $value = "%{$value}%";
             $op = 'LIKE';
         }
         $wc = 'civicrm_website.url';
         $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}'");
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } elseif ($name === 'contact_is_deleted') {
         $this->_where[$grouping][] = self::buildClause("contact_a.is_deleted", $op, $value);
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } else {
         // sometime the value is an array, need to investigate and fix
         if (is_array($value)) {
             CRM_Core_Error::fatal();
         }
         if (!empty($field['where'])) {
             if ($op != 'IN') {
                 $value = $strtolower(CRM_Core_DAO::escapeString($value));
             }
             if ($wildcard) {
                 $value = "'%{$value}%'";
                 $op = 'LIKE';
             }
             if (isset($locType[1]) && is_numeric($locType[1])) {
                 $setTables = FALSE;
                 //get the location name
                 $locationType = CRM_Core_PseudoConstant::locationType();
                 list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
                 $where = "`{$tName}`.{$fldName}";
                 $this->_where[$grouping][] = self::buildClause("LOWER({$where})", $op, $value);
                 $this->_whereTables[$tName] = $this->_tables[$tName];
                 $this->_qill[$grouping][] = "{$field['title']} {$op} '{$value}'";
             } else {
                 list($tableName, $fieldName) = explode('.', $field['where'], 2);
                 if ($tableName == 'civicrm_contact') {
                     $fieldName = "LOWER(contact_a.{$fieldName})";
                 } else {
                     if ($op != 'IN' && !is_numeric($value)) {
                         $fieldName = "LOWER({$field['where']})";
                     } else {
                         $fieldName = "{$field['where']}";
                     }
                 }
                 $type = NULL;
                 if (CRM_Utils_Array::value('type', $field)) {
                     $type = CRM_Utils_Type::typeToString($field['type']);
                 }
                 $this->_where[$grouping][] = self::buildClause($fieldName, $op, $value, $type);
                 $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}";
             }
         }
     }
     if ($setTables) {
         list($tableName, $fieldName) = explode('.', $field['where'], 2);
         if (isset($tableName)) {
             $this->_tables[$tableName] = 1;
             $this->_whereTables[$tableName] = 1;
         }
     }
 }
コード例 #8
0
 /**
  * Function to build profile form
  *
  * @params object  $form       form object
  * @params array   $field      array field properties
  * @params int     $mode       profile mode
  * @params int     $contactID  contact id
  *
  * @return null
  * @static
  * @access public
  */
 static function buildProfile(&$form, &$field, $mode, $contactId = NULL, $online = FALSE, $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+=\'&amp;confirmed=1\'; else return false;"'));
         $deleteURL = CRM_Core_Action::formLink($deleteURL, CRM_Core_Action::DELETE, array('id' => $form->get('id'), 'gid' => $form->get('gid')));
         $form->assign('deleteURL', $deleteURL);
     }
     $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE);
     if (substr($fieldName, 0, 14) === 'state_province') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required);
     } elseif (substr($fieldName, 0, 7) === 'country') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required);
         $config = CRM_Core_Config::singleton();
         if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactCountry) {
             $defaultValues[$name] = $config->defaultContactCountry;
             $form->setDefaults($defaultValues);
         }
     } elseif (substr($fieldName, 0, 6) === 'county') {
         if ($addressOptions['county']) {
             $form->add('select', $name, $title, array('' => ts('- select state -')), $required);
         }
     } elseif (substr($fieldName, 0, 9) === 'image_URL') {
         $form->add('file', $name, $title, $attributes, $required);
         $form->addUploadElement($name);
     } elseif (substr($fieldName, 0, 2) === 'im') {
         $form->add('text', $name, $title, $attributes, $required);
         if (!$contactId) {
             if ($onBehalf) {
                 if (substr($name, -1) == ']') {
                     $providerName = substr($name, 0, -1) . '-provider_id]';
                 }
                 $form->add('select', $providerName, NULL, array('' => ts('- select -')) + CRM_Core_PseudoConstant::IMProvider(), $required);
             } else {
                 $form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::IMProvider(), $required);
             }
             if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) {
                 $form->freeze($name . '-provider_id');
             }
         }
     } elseif ($fieldName === 'birth_date' || $fieldName === 'deceased_date') {
         $form->addDate($name, $title, $required, array('formatType' => 'birth'));
     } elseif (in_array($fieldName, array('membership_start_date', 'membership_end_date', 'join_date'))) {
         $form->addDate($name, $title, $required, array('formatType' => 'custom'));
     } elseif ($field['name'] == 'membership_type') {
         list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo();
         $sel =& $form->addElement('hierselect', $name, $title);
         $select = array('' => ts('- select -'));
         $sel->setOptions(array($select + $orgInfo, $types));
     } elseif ($field['name'] == 'membership_status') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), $required);
     } elseif ($fieldName === 'gender') {
         $genderOptions = array();
         $gender = CRM_Core_PseudoConstant::gender();
         foreach ($gender as $key => $var) {
             $genderOptions[$key] = $form->createElement('radio', NULL, ts('Gender'), $var, $key);
         }
         $form->addGroup($genderOptions, $name, $title);
         if ($required) {
             $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required');
         }
     } elseif ($fieldName === 'individual_prefix') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required);
     } elseif ($fieldName === 'individual_suffix') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required);
     } elseif ($fieldName === 'contact_sub_type') {
         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $form->_fields[$fieldName]);
         if ($onBehalf) {
             $profileType = 'Organization';
         } else {
             $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL;
         }
         $setSubtype = FALSE;
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $setSubtype = $profileType;
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         $subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array();
         if ($setSubtype) {
             $subtypeList = array();
             $subtypeList[$setSubtype] = $subtypes[$setSubtype];
         } else {
             $subtypeList = $subtypes;
         }
         $sel = $form->add('select', $name, $title, $subtypeList, $required);
         $sel->setMultiple(TRUE);
     } elseif (in_array($fieldName, CRM_Contact_BAO_Contact::$_greetingTypes)) {
         //add email greeting, postal greeting, addressee, CRM-4575
         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
         $profileType = CRM_Core_BAO_UFField::getProfileType($gId, TRUE, FALSE, TRUE);
         if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) {
             $profileType = 'Individual';
         }
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         $greeting = array('contact_type' => $profileType, 'greeting_type' => $fieldName);
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($greeting), $required);
         // add custom greeting element
         $form->add('text', $fieldName . '_custom', ts('Custom %1', array(1 => ucwords(str_replace('_', ' ', $fieldName)))), NULL, FALSE);
     } elseif ($fieldName === 'preferred_communication_method') {
         $communicationFields = CRM_Core_PseudoConstant::pcm();
         foreach ($communicationFields as $key => $var) {
             if ($key == '') {
                 continue;
             }
             $communicationOptions[] = $form->createElement('checkbox', $key, NULL, $var);
         }
         $form->addGroup($communicationOptions, $name, $title, '<br/>');
     } elseif ($fieldName === 'preferred_mail_format') {
         $form->add('select', $name, $title, CRM_Core_SelectValues::pmf());
     } elseif ($fieldName === 'preferred_language') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::languages());
     } elseif ($fieldName == 'external_identifier') {
         $form->add('text', $name, $title, $attributes, $required);
         $contID = $contactId;
         if (!$contID) {
             $contID = $form->get('id');
         }
         $form->addRule($name, ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $contID, 'external_identifier'));
     } elseif ($fieldName === 'group') {
         CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, TRUE, $required, $title, NULL, $name);
     } elseif ($fieldName === 'tag') {
         CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::TAG, FALSE, $required, NULL, $title, $name);
     } elseif (substr($fieldName, 0, 4) === 'url-') {
         $form->addElement('text', $name, $title, array_merge(CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), array('onfocus' => "if (!this.value) {  this.value='http://';} else return false", 'onblur' => "if ( this.value == 'http://') {  this.value='';} else return false")));
         $form->addRule($name, ts('Enter a valid Website.'), 'url');
         //Website type select
         if ($onBehalf) {
             if (substr($name, -1) == ']') {
                 $websiteTypeName = substr($name, 0, -1) . '-website_type_id]';
             }
             $form->addElement('select', $websiteTypeName, NULL, CRM_Core_PseudoConstant::websiteType());
         } else {
             $form->addElement('select', $name . '-website_type_id', NULL, CRM_Core_PseudoConstant::websiteType());
         }
         // added because note appeared as a standard text input
     } elseif ($fieldName == 'note') {
         $form->add('textarea', $name, $title, $attributes, $required);
     } elseif (substr($fieldName, 0, 6) === 'custom') {
         $customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName);
         if ($customFieldID) {
             CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title);
         }
     } elseif (substr($fieldName, 0, 14) === 'address_custom') {
         list($fName, $locTypeId) = CRM_Utils_System::explode('-', $fieldName, 2);
         $customFieldID = CRM_Core_BAO_CustomField::getKeyID(substr($fName, 8));
         if ($customFieldID) {
             CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title);
         }
     } elseif (in_array($fieldName, array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) {
         $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
     } elseif ($fieldName == 'send_receipt') {
         $form->addElement('checkbox', $name, $title);
     } elseif ($fieldName == 'soft_credit') {
         CRM_Contact_Form_NewContact::buildQuickForm($form, $rowNumber, NULL, FALSE, 'soft_credit_');
     } elseif ($fieldName == 'product_name') {
         list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo();
         $sel =& $form->addElement('hierselect', $name, $title);
         $products = array('0' => ts('- select -')) + $products;
         $sel->setOptions(array($products, $options));
     } elseif ($fieldName == 'payment_instrument') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required);
     } elseif ($fieldName == 'contribution_type') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType(), $required);
     } elseif ($fieldName == 'contribution_status_id') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionStatus(), $required);
     } elseif ($fieldName == 'currency') {
         $form->addCurrency($name, $title, $required);
     } elseif ($fieldName == 'contribution_page_id') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage(), $required, 'class="big"');
     } elseif ($fieldName == 'participant_register_date') {
         $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
     } elseif ($fieldName == 'activity_status_id') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::activityStatus(), $required);
     } elseif ($fieldName == 'activity_engagement_level') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Campaign_PseudoConstant::engagementLevel(), $required);
     } elseif ($fieldName == 'activity_date_time') {
         $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
     } elseif ($fieldName == 'participant_status') {
         $cond = NULL;
         if ($online == TRUE) {
             $cond = 'visibility_id = 1';
         }
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(NULL, $cond, 'label'), $required);
     } elseif ($fieldName == 'participant_role') {
         if (CRM_Utils_Array::value('is_multiple', $field)) {
             $form->addCheckBox($name, $title, CRM_Event_PseudoConstant::participantRole(), NULL, NULL, NULL, NULL, '&nbsp', TRUE);
         } else {
             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), $required);
         }
     } elseif ($fieldName == 'scholarship_type_id') {
         $form->add('select', $name, $title, array('' => '-- Select -- ') + array_flip(CRM_Core_OptionGroup::values('scholarship_type', TRUE)));
     } elseif ($fieldName == 'applicant_status_id') {
         $form->add('select', $name, $title, array('' => '-- Select -- ') + array_flip(CRM_Core_OptionGroup::values('applicant_status', TRUE)));
     } elseif ($fieldName == 'highschool_gpa_id') {
         $form->add('select', $name, $title, array('' => '-- Select -- ') + CRM_Core_OptionGroup::values('highschool_gpa'));
     } elseif ($fieldName == 'world_region') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::worldRegion(), $required);
     } elseif ($fieldName == 'signature_html') {
         $form->addWysiwyg($name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName));
     } elseif ($fieldName == 'signature_text') {
         $form->add('textarea', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName));
     } elseif (substr($fieldName, -11) == 'campaign_id') {
         if (CRM_Campaign_BAO_Campaign::isCampaignEnable()) {
             $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(CRM_Utils_Array::value($contactId, $form->_componentCampaigns));
             $campaign =& $form->add('select', $name, $title, array('' => ts('- select -')) + $campaigns, $required, 'class="big"');
         }
     } elseif ($fieldName == 'activity_details') {
         $form->addWysiwyg($fieldName, $title, array('rows' => 4, 'cols' => 60), $required);
     } elseif ($fieldName == 'activity_duration') {
         $form->add('text', $fieldName, $title, $attributes, $required);
         $form->addRule($name, ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger');
     } else {
         $processed = FALSE;
         if (CRM_Core_Permission::access('Quest', FALSE)) {
             $processed = CRM_Quest_BAO_Student::buildStudentForm($form, $fieldName, $title, $contactId);
         }
         if (!$processed) {
             if (substr($fieldName, 0, 3) === 'is_' or substr($fieldName, 0, 7) === 'do_not_') {
                 $form->add('advcheckbox', $name, $title, $attributes, $required);
             } else {
                 $form->add('text', $name, $title, $attributes, $required);
             }
         }
     }
     static $hiddenSubtype = FALSE;
     if (!$hiddenSubtype && CRM_Contact_BAO_ContactType::isaSubType($field['field_type'])) {
         // In registration mode params are submitted via POST and we don't have any clue
         // about profile-id or the profile-type (which could be a subtype)
         // To generalize the  behavior and simplify the process,
         // lets always add the hidden
         //subtype value if there is any, and we won't have to
         // compute it while processing.
         if ($onBehalf) {
             $form->addElement('hidden', 'onbehalf[contact_sub_type]', $field['field_type']);
         } else {
             $form->addElement('hidden', 'contact_sub_type_hidden', $field['field_type']);
         }
         $hiddenSubtype = TRUE;
     }
     if ($view && $mode != CRM_Profile_Form::MODE_SEARCH || $isShared) {
         $form->freeze($name);
     }
     //add the rules
     if (in_array($fieldName, array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) {
         $form->addRule($name, ts('Please enter a valid amount.'), 'money');
     }
     if ($rule) {
         if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) {
             $form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule);
         }
     }
 }
コード例 #9
0
ファイル: utils.php プロジェクト: ksecor/civicrm
/**
 * 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;
            }
        }
    }
}
コード例 #10
0
ファイル: Export.php プロジェクト: ksecor/civicrm
 /**
  * Function to get the list the export fields
  *
  * @param int    $selectAll user preference while export
  * @param array  $ids  contact ids
  * @param array  $params associated array of fields
  * @param string $order order by clause
  * @param array  $associated array of fields
  * @param array  $moreReturnProperties additional return fields
  * @param int    $exportMode export mode
  * @param string $componentClause component clause
  *
  * @static
  * @access public
  */
 static function exportComponents($selectAll, $ids, $params, $order = null, $fields = null, $moreReturnProperties = null, $exportMode = CRM_Export_Form_Select::CONTACT_EXPORT, $componentClause = null)
 {
     $headerRows = array();
     $primary = false;
     $returnProperties = array();
     $origFields = $fields;
     $queryMode = null;
     $paymentFields = false;
     $phoneTypes = CRM_Core_PseudoConstant::phoneType();
     $imProviders = CRM_Core_PseudoConstant::IMProvider();
     $contactRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, null, null, null, true, 'label', false);
     $queryMode = CRM_Contact_BAO_Query::MODE_CONTACTS;
     switch ($exportMode) {
         case CRM_Export_Form_Select::CONTRIBUTE_EXPORT:
             $queryMode = CRM_Contact_BAO_Query::MODE_CONTRIBUTE;
             break;
         case CRM_Export_Form_Select::EVENT_EXPORT:
             $queryMode = CRM_Contact_BAO_Query::MODE_EVENT;
             break;
         case CRM_Export_Form_Select::MEMBER_EXPORT:
             $queryMode = CRM_Contact_BAO_Query::MODE_MEMBER;
             break;
         case CRM_Export_Form_Select::PLEDGE_EXPORT:
             $queryMode = CRM_Contact_BAO_Query::MODE_PLEDGE;
             break;
         case CRM_Export_Form_Select::CASE_EXPORT:
             $queryMode = CRM_Contact_BAO_Query::MODE_CASE;
             break;
     }
     require_once 'CRM/Core/BAO/CustomField.php';
     if ($fields) {
         //construct return properties
         $locationTypes =& CRM_Core_PseudoConstant::locationType();
         $locationTypeFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'geo_code_1', 'geo_code_2', 'state_province', 'country', 'phone', 'email', 'im');
         foreach ($fields as $key => $value) {
             $phoneTypeId = null;
             $imProviderId = null;
             $relationshipTypes = $fieldName = CRM_Utils_Array::value(1, $value);
             if (!$fieldName) {
                 continue;
             }
             // get phoneType id and IM service provider id seperately
             if ($fieldName == 'phone') {
                 $phoneTypeId = CRM_Utils_Array::value(3, $value);
             } else {
                 if ($fieldName == 'im') {
                     $imProviderId = CRM_Utils_Array::value(3, $value);
                 }
             }
             if (array_key_exists($relationshipTypes, $contactRelationshipTypes)) {
                 if (CRM_Utils_Array::value(2, $value)) {
                     $relationField = CRM_Utils_Array::value(2, $value);
                     if (trim(CRM_Utils_Array::value(3, $value))) {
                         $relLocTypeId = CRM_Utils_Array::value(3, $value);
                     } else {
                         $relLocTypeId = 1;
                     }
                     if ($relationField == 'phone') {
                         $relPhoneTypeId = CRM_Utils_Array::value(4, $value);
                     } else {
                         if ($relationField == 'im') {
                             $relIMProviderId = CRM_Utils_Array::value(4, $value);
                         }
                     }
                 } else {
                     if (CRM_Utils_Array::value(4, $value)) {
                         $relationField = CRM_Utils_Array::value(4, $value);
                         $relLocTypeId = CRM_Utils_Array::value(5, $value);
                         if ($relationField == 'phone') {
                             $relPhoneTypeId = CRM_Utils_Array::value(6, $value);
                         } else {
                             if ($relationField == 'im') {
                                 $relIMProviderId = CRM_Utils_Array::value(6, $value);
                             }
                         }
                     }
                 }
             }
             $contactType = CRM_Utils_Array::value(0, $value);
             $locTypeId = CRM_Utils_Array::value(2, $value);
             $phoneTypeId = CRM_Utils_Array::value(3, $value);
             if ($relationField) {
                 if (in_array($relationField, $locationTypeFields)) {
                     if ($relPhoneTypeId) {
                         $returnProperties[$relationshipTypes]['location'][$locationTypes[$relLocTypeId]]['phone-' . $relPhoneTypeId] = 1;
                     } else {
                         if ($relIMProviderId) {
                             $returnProperties[$relationshipTypes]['location'][$locationTypes[$relLocTypeId]]['im-' . $relIMProviderId] = 1;
                         } else {
                             $returnProperties[$relationshipTypes]['location'][$locationTypes[$relLocTypeId]][$relationField] = 1;
                         }
                     }
                     $relPhoneTypeId = $relIMProviderId = null;
                 } else {
                     $returnProperties[$relationshipTypes][$relationField] = 1;
                 }
             } else {
                 if (is_numeric($locTypeId)) {
                     if ($phoneTypeId) {
                         $returnProperties['location'][$locationTypes[$locTypeId]]['phone-' . $phoneTypeId] = 1;
                     } else {
                         if (isset($imProviderId)) {
                             //build returnProperties for IM service provider
                             $returnProperties['location'][$locationTypes[$locTypeId]]['im-' . $imProviderId] = 1;
                         } else {
                             $returnProperties['location'][$locationTypes[$locTypeId]][$fieldName] = 1;
                         }
                     }
                 } else {
                     //hack to fix component fields
                     if ($fieldName == 'event_id') {
                         $returnProperties['event_title'] = 1;
                     } else {
                         $returnProperties[$fieldName] = 1;
                     }
                 }
             }
         }
         // hack to add default returnproperty based on export mode
         if ($exportMode == CRM_Export_Form_Select::CONTRIBUTE_EXPORT) {
             $returnProperties['contribution_id'] = 1;
         } else {
             if ($exportMode == CRM_Export_Form_Select::EVENT_EXPORT) {
                 $returnProperties['participant_id'] = 1;
             } else {
                 if ($exportMode == CRM_Export_Form_Select::MEMBER_EXPORT) {
                     $returnProperties['membership_id'] = 1;
                 } else {
                     if ($exportMode == CRM_Export_Form_Select::PLEDGE_EXPORT) {
                         $returnProperties['pledge_id'] = 1;
                     } else {
                         if ($exportMode == CRM_Export_Form_Select::CASE_EXPORT) {
                             $returnProperties['case_id'] = 1;
                         }
                     }
                 }
             }
         }
     } else {
         $primary = true;
         $fields = CRM_Contact_BAO_Contact::exportableFields('All', true, true);
         foreach ($fields as $key => $var) {
             if ($key && substr($key, 0, 6) != 'custom') {
                 //for CRM=952
                 $returnProperties[$key] = 1;
             }
         }
         if ($primary) {
             $returnProperties['location_type'] = 1;
             $returnProperties['im_provider'] = 1;
             $returnProperties['phone_type_id'] = 1;
             $returnProperties['provider_id'] = 1;
             $returnProperties['current_employer'] = 1;
         }
         $extraReturnProperties = array();
         $paymentFields = false;
         switch ($queryMode) {
             case CRM_Contact_BAO_Query::MODE_EVENT:
                 $paymentFields = true;
                 $paymentTableId = "participant_id";
                 break;
             case CRM_Contact_BAO_Query::MODE_MEMBER:
                 $paymentFields = true;
                 $paymentTableId = "membership_id";
                 break;
             case CRM_Contact_BAO_Query::MODE_PLEDGE:
                 require_once 'CRM/Pledge/BAO/Query.php';
                 $extraReturnProperties = CRM_Pledge_BAO_Query::extraReturnProperties($queryMode);
                 $paymentFields = true;
                 $paymentTableId = "pledge_payment_id";
                 break;
             case CRM_Contact_BAO_Query::MODE_CASE:
                 require_once 'CRM/Case/BAO/Query.php';
                 $extraReturnProperties = CRM_Case_BAO_Query::extraReturnProperties($queryMode);
                 break;
         }
         if ($queryMode != CRM_Contact_BAO_Query::MODE_CONTACTS) {
             $componentReturnProperties =& CRM_Contact_BAO_Query::defaultReturnProperties($queryMode);
             $returnProperties = array_merge($returnProperties, $componentReturnProperties);
             if (!empty($extraReturnProperties)) {
                 $returnProperties = array_merge($returnProperties, $extraReturnProperties);
             }
             // unset groups, tags, notes for components
             foreach (array('groups', 'tags', 'notes') as $value) {
                 unset($returnProperties[$value]);
             }
         }
     }
     if ($moreReturnProperties) {
         $returnProperties = array_merge($returnProperties, $moreReturnProperties);
     }
     $query =& new CRM_Contact_BAO_Query(0, $returnProperties, null, false, false, $queryMode);
     list($select, $from, $where) = $query->query();
     // make sure the groups stuff is included only if specifically specified
     // by the fields param (CRM-1969), else we limit the contacts outputted to only
     // ones that are part of a group
     if (CRM_Utils_Array::value('groups', $returnProperties)) {
         $oldClause = "contact_a.id = civicrm_group_contact.contact_id";
         $newClause = " ( {$oldClause} AND civicrm_group_contact.status = 'Added' OR civicrm_group_contact.status IS NULL ) ";
         // total hack for export, CRM-3618
         $from = str_replace($oldClause, $newClause, $from);
     }
     if ($componentClause) {
         if (empty($where)) {
             $where = "WHERE {$componentClause}";
         } else {
             $where .= " AND {$componentClause}";
         }
     }
     $queryString = "{$select} {$from} {$where}";
     if (CRM_Utils_Array::value('tags', $returnProperties) || CRM_Utils_Array::value('groups', $returnProperties) || CRM_Utils_Array::value('notes', $returnProperties) || $query->_useGroupBy) {
         $queryString .= " GROUP BY contact_a.id";
     }
     if ($order) {
         list($field, $dir) = explode(' ', $order, 2);
         $field = trim($field);
         if (CRM_Utils_Array::value($field, $returnProperties)) {
             $queryString .= " ORDER BY {$order}";
         }
     }
     //hack for student data
     require_once 'CRM/Core/OptionGroup.php';
     $multipleSelectFields = array('preferred_communication_method' => 1);
     if (CRM_Core_Permission::access('Quest')) {
         require_once 'CRM/Quest/BAO/Student.php';
         $studentFields = array();
         $studentFields = CRM_Quest_BAO_Student::$multipleSelectFields;
         $multipleSelectFields = array_merge($multipleSelectFields, $studentFields);
     }
     $dao =& CRM_Core_DAO::executeQuery($queryString, CRM_Core_DAO::$_nullArray);
     $header = false;
     $addPaymentHeader = false;
     if ($paymentFields) {
         $addPaymentHeader = true;
         //special return properties for event and members
         $paymentHeaders = array(ts('Total Amount'), ts('Contribution Status'), ts('Received Date'), ts('Payment Instrument'), ts('Transaction ID'));
         // get payment related in for event and members
         require_once 'CRM/Contribute/BAO/Contribution.php';
         $paymentDetails = CRM_Contribute_BAO_Contribution::getContributionDetails($exportMode, $ids);
     }
     $componentDetails = $headerRows = array();
     $setHeader = true;
     while ($dao->fetch()) {
         $row = array();
         //first loop through returnproperties so that we return what is required, and in same order.
         $relationshipField = 0;
         foreach ($returnProperties as $field => $value) {
             //we should set header only once
             if ($setHeader) {
                 if (isset($query->_fields[$field]['title'])) {
                     $headerRows[] = $query->_fields[$field]['title'];
                 } else {
                     if ($field == 'phone_type_id') {
                         $headerRows[] = 'Phone Type';
                     } else {
                         if ($field == 'provider_id') {
                             $headerRows[] = 'Im Service Provider';
                         } else {
                             if (is_array($value) && $field == 'location') {
                                 // fix header for location type case
                                 foreach ($value as $ltype => $val) {
                                     foreach (array_keys($val) as $fld) {
                                         $type = explode('-', $fld);
                                         $hdr = "{$ltype}-" . $query->_fields[$type[0]]['title'];
                                         if (CRM_Utils_Array::value(1, $type)) {
                                             if (CRM_Utils_Array::value(0, $type) == 'phone') {
                                                 $hdr .= "-" . CRM_Utils_Array::value($type[1], $phoneTypes);
                                             } else {
                                                 if (CRM_Utils_Array::value(0, $type) == 'im') {
                                                     $hdr .= "-" . CRM_Utils_Array::value($type[1], $imProviders);
                                                 }
                                             }
                                         }
                                         $headerRows[] = $hdr;
                                     }
                                 }
                             } else {
                                 if (substr($field, 0, 5) == 'case_') {
                                     if ($query->_fields['case'][$field]['title']) {
                                         $headerRows[] = $query->_fields['case'][$field]['title'];
                                     } else {
                                         if ($query->_fields['activity'][$field]['title']) {
                                             $headerRows[] = $query->_fields['activity'][$field]['title'];
                                         }
                                     }
                                 } else {
                                     if (array_key_exists($field, $contactRelationshipTypes)) {
                                         foreach ($value as $relationField => $relationValue) {
                                             if (is_array($relationValue)) {
                                                 foreach ($relationValue as $locType => $locValue) {
                                                     if ($relationField == 'location') {
                                                         foreach ($locValue as $locKey => $dont) {
                                                             list($serviceProvider, $serviceProviderID) = explode('-', $locKey);
                                                             if ($serviceProvider == 'phone') {
                                                                 $headerRows[] = $contactRelationshipTypes[$field] . ' : ' . $locType . ' - ' . $serviceProvider . ' - ' . CRM_Utils_Array::value($serviceProviderID, $phoneTypes, 'Primary');
                                                             } else {
                                                                 if ($serviceProvider == 'im') {
                                                                     $headerRows[] = $contactRelationshipTypes[$field] . ' : ' . $locType . ' - ' . $serviceProvider . ' - ' . CRM_Utils_Array::value($serviceProviderID, $imProviders, 'Primary');
                                                                 } else {
                                                                     $headerRows[] = $contactRelationshipTypes[$field] . ' : ' . $locType . ' - ' . $query->_fields[$locKey]['title'];
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             } else {
                                                 if ($query->_fields[$relationField]['title']) {
                                                     $headerRows[] = $contactRelationshipTypes[$field] . ' : ' . $query->_fields[$relationField]['title'];
                                                 } else {
                                                     $headerRows[] = $contactRelationshipTypes[$field] . ' : ' . $relationField;
                                                 }
                                             }
                                         }
                                     } else {
                                         $headerRows[] = $field;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             //build row values (data)
             if (property_exists($dao, $field)) {
                 $fieldValue = $dao->{$field};
                 // to get phone type from phone type id
                 if ($field == 'phone_type_id') {
                     $fieldValue = $phoneTypes[$fieldValue];
                 } else {
                     if ($field == 'provider_id') {
                         $fieldValue = CRM_Utils_Array::value($fieldValue, $imProviders);
                     }
                 }
             } else {
                 $fieldValue = '';
             }
             if ($field == 'id') {
                 $row[$field] = $dao->contact_id;
             } else {
                 if ($field == 'pledge_balance_amount') {
                     //special case for calculated field
                     $row[$field] = $dao->pledge_amount - $dao->pledge_total_paid;
                 } else {
                     if ($field == 'pledge_next_pay_amount') {
                         //special case for calculated field
                         $row[$field] = $dao->pledge_next_pay_amount + $dao->pledge_outstanding_amount;
                     } else {
                         if (is_array($value) && $field == 'location') {
                             // fix header for location type case
                             foreach ($value as $ltype => $val) {
                                 foreach (array_keys($val) as $fld) {
                                     $type = explode('-', $fld);
                                     $fldValue = "{$ltype}-" . $type[0];
                                     if (CRM_Utils_Array::value(1, $type)) {
                                         $fldValue .= "-" . $type[1];
                                     }
                                     $row[$fldValue] = $dao->{$fldValue};
                                 }
                             }
                         } else {
                             if (array_key_exists($field, $contactRelationshipTypes)) {
                                 list($id, $direction) = explode('_', $field, 2);
                                 require_once 'api/v2/Relationship.php';
                                 require_once 'CRM/Contact/BAO/Contact.php';
                                 require_once 'CRM/Core/BAO/CustomValueTable.php';
                                 require_once 'CRM/Core/BAO/CustomQuery.php';
                                 $params['relationship_type_id'] = $contactRelationshipTypes[$field];
                                 $contact_id['contact_id'] = $dao->contact_id;
                                 //Get relationships
                                 $val = civicrm_contact_relationship_get($contact_id, null, $params);
                                 if (is_array($val['result'])) {
                                     asort($val['result']);
                                 }
                                 $is_valid = null;
                                 $data = null;
                                 if ($val['result']) {
                                     foreach ($val['result'] as $k => $v) {
                                         //consider only active relationships
                                         if ($v['is_active'] && $v['rtype'] == $direction) {
                                             $cID['contact_id'] = $v['cid'];
                                             if ($cID) {
                                                 //Get Contact Details
                                                 $data = CRM_Contact_BAO_Contact::retrieve($cID, $defaults);
                                             }
                                             $is_valid = true;
                                             break;
                                         }
                                     }
                                 }
                                 $relCustomIDs = array();
                                 foreach ($value as $relationkey => $relationvalue) {
                                     if ($val['result'] && ($cfID = CRM_Core_BAO_CustomField::getKeyID($relationkey))) {
                                         foreach ($val['result'] as $k1 => $v1) {
                                             $contID = $v1['cid'];
                                             $param1 = array('entityID' => $contID, $relationkey => 1);
                                             $getcustomValue = CRM_Core_BAO_CustomValueTable::getValues($param1);
                                             $custom_ID = CRM_Core_BAO_CustomField::getKeyID($relationkey);
                                             if ($cfID = CRM_Core_BAO_CustomField::getKeyID($relationkey)) {
                                                 if (empty($query->_options)) {
                                                     $relCustomIDs[$cfID] = array();
                                                     $relQuery = new CRM_Core_BAO_CustomQuery($relCustomIDs);
                                                     $relQuery->query();
                                                     $relOptions = $relQuery->_options;
                                                 } else {
                                                     $relOptions = $query->_options;
                                                 }
                                                 $custom_data = CRM_Core_BAO_CustomField::getDisplayValue($getcustomValue[$relationkey], $cfID, $relOptions);
                                             } else {
                                                 $custom_data = '';
                                             }
                                         }
                                     }
                                     //Get all relationships type custom fields
                                     list($id, $atype, $btype) = explode('_', $field);
                                     $relCustomData = CRM_Core_BAO_CustomField::getFields('Relationship', null, null, $id, null, null);
                                     $tmpArray = array_keys($relCustomData);
                                     $customIDs = array();
                                     foreach ($tmpArray as $customID) {
                                         $customIDs[$customID] = array();
                                     }
                                     require_once 'CRM/Core/BAO/CustomQuery.php';
                                     $customQuery = new CRM_Core_BAO_CustomQuery($customIDs);
                                     $customQuery->query();
                                     $options = $customQuery->_options;
                                     foreach ($relCustomData as $id => $customdatavalue) {
                                         if (in_array($relationkey, $customdatavalue)) {
                                             $customkey = "custom_{$id}";
                                             if ($val['result']) {
                                                 foreach ($val['result'] as $k => $v) {
                                                     $cid = $v['id'];
                                                     $param = array('entityID' => $cid, $customkey => 1);
                                                     //Get custom data values
                                                     $getCustomValueRel = CRM_Core_BAO_CustomValueTable::getValues($param);
                                                     if (!array_key_exists('error_message', $getCustomValueRel)) {
                                                         $customData = CRM_Core_BAO_CustomField::getDisplayValue($getCustomValueRel[$customkey], $id, $options);
                                                     } else {
                                                         $customData = '';
                                                     }
                                                     if ($customData) {
                                                         break;
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                     if (is_array($relationvalue)) {
                                         if (array_key_exists('location', $value)) {
                                             foreach ($value['location'] as $columnkey => $columnvalue) {
                                                 foreach ($columnvalue as $colkey => $colvalue) {
                                                     list($serviceProvider, $serviceProviderID) = explode('-', $colkey);
                                                     if (in_array($serviceProvider, array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'state_province', 'country'))) {
                                                         $serviceProvider = 'address';
                                                     }
                                                     $output = null;
                                                     foreach ((array) $data->{$serviceProvider} as $datakey => $datavalue) {
                                                         if ($columnkey == 'Primary') {
                                                             $columnkey = $locationTypes[$datavalue['location_type_id']];
                                                         }
                                                         if ($locationTypes[$datavalue['location_type_id']] == $columnkey) {
                                                             if (array_key_exists($colkey, $datavalue)) {
                                                                 $output = $datavalue[$colkey];
                                                             } else {
                                                                 if ($colkey == 'country') {
                                                                     $countryId = $datavalue['country_id'];
                                                                     if ($countryId) {
                                                                         require_once 'CRM/Core/PseudoConstant.php';
                                                                         $country =& CRM_Core_PseudoConstant::country($countryId);
                                                                     } else {
                                                                         $country = '';
                                                                     }
                                                                     $output = $country;
                                                                 } else {
                                                                     if ($colkey == 'state_province') {
                                                                         $stateProvinceId = $datavalue['state_province_id'];
                                                                         if ($stateProvinceId) {
                                                                             $stateProvince =& CRM_Core_PseudoConstant::stateProvince($stateProvinceId);
                                                                         } else {
                                                                             $stateProvince = '';
                                                                         }
                                                                         $output = $stateProvince;
                                                                     } else {
                                                                         if (is_numeric($serviceProviderID)) {
                                                                             if ($serviceProvider == 'phone') {
                                                                                 if (isset($datavalue['phone'])) {
                                                                                     $output = $datavalue['phone'];
                                                                                 } else {
                                                                                     $output = '';
                                                                                 }
                                                                             } else {
                                                                                 if ($serviceProvider == 'im') {
                                                                                     if (isset($datavalue['name'])) {
                                                                                         $output = $datavalue['name'];
                                                                                     } else {
                                                                                         $output = '';
                                                                                     }
                                                                                 }
                                                                             }
                                                                         } else {
                                                                             if ($datavalue['location_type_id']) {
                                                                                 if ($colkey == 'im') {
                                                                                     $output = $datavalue['name'];
                                                                                 } else {
                                                                                     $output = $datavalue[$colkey];
                                                                                 }
                                                                             } else {
                                                                                 $output = '';
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                     if ($is_valid) {
                                                         $row[] = $output;
                                                     } else {
                                                         $row[] = '';
                                                     }
                                                 }
                                             }
                                         }
                                     } else {
                                         if ($cfID = CRM_Core_BAO_CustomField::getKeyID($relationkey) && $is_valid) {
                                             $row[] = $custom_data;
                                         } else {
                                             if ($query->_fields[$relationkey]['name'] && $is_valid) {
                                                 if ($query->_fields[$relationkey]['name'] == 'gender') {
                                                     $getGenders =& CRM_Core_PseudoConstant::gender();
                                                     $gender = array_search($data->gender_id, array_flip($getGenders));
                                                     $row[] = $gender;
                                                 } else {
                                                     if ($query->_fields[$relationkey]['name'] == 'greeting_type') {
                                                         $getgreeting =& CRM_Core_PseudoConstant::greeting();
                                                         $greeting = array_search($data->greeting_type_id, array_flip($getgreeting));
                                                         $row[] = $greeting;
                                                     } else {
                                                         $colValue = $query->_fields[$relationkey]['name'];
                                                         $row[] = $data->{$colValue};
                                                     }
                                                 }
                                             } else {
                                                 if ($customData && $is_valid) {
                                                     $row[] = $customData;
                                                 } else {
                                                     $row[] = '';
                                                 }
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 if (isset($fieldValue) && $fieldValue != '') {
                                     //check for custom data
                                     if ($cfID = CRM_Core_BAO_CustomField::getKeyID($field)) {
                                         $row[$field] = CRM_Core_BAO_CustomField::getDisplayValue($fieldValue, $cfID, $query->_options);
                                     } else {
                                         if (array_key_exists($field, $multipleSelectFields)) {
                                             //option group fixes
                                             $paramsNew = array($field => $fieldValue);
                                             if ($field == 'test_tutoring') {
                                                 $name = array($field => array('newName' => $field, 'groupName' => 'test'));
                                             } else {
                                                 if (substr($field, 0, 4) == 'cmr_') {
                                                     //for  readers group
                                                     $name = array($field => array('newName' => $field, 'groupName' => substr($field, 0, -3)));
                                                 } else {
                                                     $name = array($field => array('newName' => $field, 'groupName' => $field));
                                                 }
                                             }
                                             CRM_Core_OptionGroup::lookupValues($paramsNew, $name, false);
                                             $row[$field] = $paramsNew[$field];
                                         } else {
                                             if (in_array($field, array('email_greeting', 'postal_greeting', 'addressee'))) {
                                                 //special case for greeting replacement
                                                 $fldValue = "{$field}_display";
                                                 $row[$field] = $dao->{$fldValue};
                                             } else {
                                                 //normal fields
                                                 $row[$field] = $fieldValue;
                                             }
                                         }
                                     }
                                 } else {
                                     // if field is empty or null
                                     $row[$field] = '';
                                 }
                             }
                         }
                     }
                 }
             }
         }
         //build header only once
         $setHeader = false;
         // add payment headers if required
         if ($addPaymentHeader && $paymentFields) {
             $headerRows = array_merge($headerRows, $paymentHeaders);
             $addPaymentHeader = false;
         }
         // add payment related information
         if ($paymentFields && isset($paymentDetails[$row[$paymentTableId]])) {
             $row = array_merge($row, $paymentDetails[$row[$paymentTableId]]);
         }
         //remove organization name for individuals if it is set for current employer
         if (CRM_Utils_Array::value('contact_type', $row) && $row['contact_type'] == 'Individual') {
             $row['organization_name'] = '';
         }
         // add component info
         $componentDetails[] = $row;
     }
     require_once 'CRM/Core/Report/Excel.php';
     CRM_Core_Report_Excel::writeCSVFile(self::getExportFileName('csv', $exportMode), $headerRows, $componentDetails);
     exit;
 }
コード例 #11
0
 /**
  * build the form elements for Communication Preferences object
  *
  * @param CRM_Core_Form $form       reference to the form object
  *
  * @return void
  * @access public
  * @static
  */
 static function buildQuickForm(&$form)
 {
     // since the pcm - preferred comminication method is logically
     // grouped hence we'll use groups of HTML_QuickForm
     // checkboxes for DO NOT phone, email, mail
     // we take labels from SelectValues
     $privacy = $commPreff = $commPreference = array();
     $privacyOptions = CRM_Core_SelectValues::privacy();
     foreach ($privacyOptions as $name => $label) {
         $privacy[] = HTML_QuickForm::createElement('advcheckbox', $name, null, $label);
     }
     $form->addGroup($privacy, 'privacy', ts('Privacy'), '&nbsp;');
     // preferred communication method
     require_once 'CRM/Core/PseudoConstant.php';
     $comm = CRM_Core_PseudoConstant::pcm();
     foreach ($comm as $value => $title) {
         $commPreff[] = HTML_QuickForm::createElement('advcheckbox', $value, null, $title);
     }
     $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Method(s)'));
     $form->add('select', 'preferred_language', ts('Preferred Language'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::languages());
     if (!empty($privacyOptions)) {
         $commPreference['privacy'] = $privacyOptions;
     }
     if (!empty($comm)) {
         $commPreference['preferred_communication_method'] = $comm;
     }
     //using for display purpose.
     $form->assign('commPreference', $commPreference);
     $form->add('select', 'preferred_mail_format', ts('Email Format'), CRM_Core_SelectValues::pmf());
     $form->add('checkbox', 'is_opt_out', ts('NO BULK EMAILS (User Opt Out)'));
     //check contact type and build filter clause accordingly for greeting types, CRM-4575
     $greetings = self::getGreetingFields($form->_contactType);
     foreach ($greetings as $greeting => $fields) {
         $filter = array('contact_type' => $form->_contactType, 'greeting_type' => $greeting);
         //add addressee in Contact form
         $greetingTokens = CRM_Core_PseudoConstant::greeting($filter);
         if (!empty($greetingTokens)) {
             $form->addElement('select', $fields['field'], $fields['label'], array('' => ts('- select -')) + $greetingTokens);
             //custom addressee
             $form->addElement('text', $fields['customField'], $fields['customLabel'], CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', $fields['customField']), $fields['js']);
         }
     }
 }
コード例 #12
0
ファイル: Contact.php プロジェクト: ksecor/civicrm
 /**
  * Function to process greetings and cache
  *
  */
 static function processGreetings(&$contact)
 {
     // store object values to an array
     $contactDetails = array();
     CRM_Core_DAO::storeValues($contact, $contactDetails);
     $contactDetails = array(array($contact->id => $contactDetails));
     $emailGreetingString = $postalGreetingString = $addresseeString = null;
     $updateQueryString = array();
     require_once 'CRM/Activity/BAO/Activity.php';
     //email greeting
     if ($contact->contact_type == 'Individual' || $contact->contact_type == 'Household') {
         if ($contact->email_greeting_custom != 'null' && $contact->email_greeting_custom) {
             $emailGreetingString = $contact->email_greeting_custom;
         } else {
             if ($contact->email_greeting_id != 'null' && $contact->email_greeting_id) {
                 // the filter value for Individual contact type is set to 1
                 $filter = array('contact_type' => $contact->contact_type, 'greeting_type' => 'email_greeting');
                 $emailGreeting = CRM_Core_PseudoConstant::greeting($filter);
                 $emailGreetingString = $emailGreeting[$contact->email_greeting_id];
             } else {
                 $updateQueryString[] = " email_greeting_display = NULL ";
             }
         }
         if ($emailGreetingString) {
             CRM_Activity_BAO_Activity::replaceGreetingTokens($emailGreetingString, $contactDetails, $contact->id);
             $emailGreetingString = CRM_Core_DAO::escapeString($emailGreetingString);
             $updateQueryString[] = " email_greeting_display = '{$emailGreetingString}'";
         }
         //postal greetings
         if ($contact->postal_greeting_custom != 'null' && $contact->postal_greeting_custom) {
             $postalGreetingString = $contact->postal_greeting_custom;
         } else {
             if ($contact->postal_greeting_id != 'null' && $contact->postal_greeting_id) {
                 $filter = array('contact_type' => $contact->contact_type, 'greeting_type' => 'postal_greeting');
                 $postalGreeting = CRM_Core_PseudoConstant::greeting($filter);
                 $postalGreetingString = $postalGreeting[$contact->postal_greeting_id];
             } elseif ($contact->postal_greeting_custom) {
                 $updateQueryString[] = " postal_greeting_display = NULL ";
             }
         }
         if ($postalGreetingString) {
             CRM_Activity_BAO_Activity::replaceGreetingTokens($postalGreetingString, $contactDetails, $contact->id);
             $postalGreetingString = CRM_Core_DAO::escapeString($postalGreetingString);
             $updateQueryString[] = " postal_greeting_display = '{$postalGreetingString}'";
         }
     }
     // addressee
     if ($contact->addressee_custom != 'null' && $contact->addressee_custom) {
         $addresseeString = $contact->addressee_custom;
     } else {
         if ($contact->addressee_id != 'null' && $contact->addressee_id) {
             $filter = array('contact_type' => $contact->contact_type, 'greeting_type' => 'addressee');
             $addressee = CRM_Core_PseudoConstant::greeting($filter);
             $addresseeString = $addressee[$contact->addressee_id];
         } else {
             $updateQueryString[] = " addressee_display = NULL ";
         }
     }
     if ($addresseeString) {
         CRM_Activity_BAO_Activity::replaceGreetingTokens($addresseeString, $contactDetails, $contact->id);
         $addresseeString = CRM_Core_DAO::escapeString($addresseeString);
         $updateQueryString[] = " addressee_display = '{$addresseeString}'";
     }
     if (!empty($updateQueryString)) {
         $updateQueryString = implode(',', $updateQueryString);
         $queryString = "UPDATE civicrm_contact SET {$updateQueryString} WHERE id = {$contact->id}";
         CRM_Core_DAO::executeQuery($queryString);
     }
 }
コード例 #13
0
ファイル: Query.php プロジェクト: ksecor/civicrm
 function restWhere(&$values)
 {
     list($name, $op, $value, $grouping, $wildcard) = $values;
     if (!CRM_Utils_Array::value($grouping, $this->_where)) {
         $this->_where[$grouping] = array();
     }
     //check if the location type exits for fields
     $lType = '';
     $locType = array();
     $locType = explode('-', $name);
     //add phone type if exists
     if (isset($locType[2]) && $locType[2]) {
         $locType[2] = CRM_Core_DAO::escapeString($locType[2]);
     }
     $field = CRM_Utils_Array::value($name, $this->_fields);
     if (!$field) {
         $field = CRM_Utils_Array::value($locType[0], $this->_fields);
         if (!$field) {
             return;
         }
     }
     $setTables = true;
     // FIXME: the LOWER/strtolower pairs below most probably won't work
     // with non-US-ASCII characters, as even if MySQL does the proper
     // thing with LOWER-ing them (4.0 almost certainly won't, but then
     // we don't officially support 4.0 for non-US-ASCII data), PHP
     // won't do the proper thing with strtolower-ing them unless the
     // underlying operating system uses an UTF-8 locale for LC_CTYPE
     // for the user the webserver runs at (or suEXECs); we should use
     // mb_strtolower(), but then we'd require mb_strings support; we
     // could wrap this in function_exist(), though
     if (substr($name, 0, 14) === 'state_province') {
         if (isset($locType[1]) && is_numeric($locType[1])) {
             $setTables = false;
             //get the location name
             $locationType =& CRM_Core_PseudoConstant::locationType();
             list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
             $this->_whereTables[$tName] = $this->_tables[$tName];
             $where = "`{$tName}`.{$fldName}";
         } else {
             $where = $field['where'];
         }
         $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
         if (is_numeric($value)) {
             $where = str_replace('.name', '.id', $where);
             $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
             $states =& CRM_Core_PseudoConstant::stateProvince();
             $value = $states[(int) $value];
         } else {
             $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
             $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         }
         if (!$lType) {
             $this->_qill[$grouping][] = ts('State') . " {$op} '{$value}'";
         } else {
             $this->_qill[$grouping][] = ts('State') . " ({$lType}) {$op} '{$value}'";
         }
     } else {
         if (substr($name, 0, 7) === 'country') {
             if (isset($locType[1]) && is_numeric($locType[1])) {
                 $setTables = false;
                 //get the location name
                 $locationType =& CRM_Core_PseudoConstant::locationType();
                 list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
                 $this->_whereTables[$tName] = $this->_tables[$tName];
                 $where = "`{$tName}`.{$fldName}";
             } else {
                 $where = $field['where'];
             }
             if (is_numeric($value)) {
                 $where = str_replace('.name', '.id', $where);
                 $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
                 $countries =& CRM_Core_PseudoConstant::country();
                 $value = $countries[(int) $value];
             } else {
                 $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
                 $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
             }
             if (!$lType) {
                 $this->_qill[$grouping][] = ts('Country') . " {$op} '{$value}'";
             } else {
                 $this->_qill[$grouping][] = ts('Country') . " ({$lType}) {$op} '{$value}'";
             }
         } else {
             if (substr($name, 0, 6) === 'county') {
                 if (isset($locType[1]) && is_numeric($locType[1])) {
                     $setTables = false;
                     //get the location name
                     $locationType =& CRM_Core_PseudoConstant::locationType();
                     list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
                     $this->_whereTables[$tName] = $this->_tables[$tName];
                     $where = "`{$tName}`.{$fldName}";
                 } else {
                     $where = $field['where'];
                 }
                 if (is_numeric($value)) {
                     $where = str_replace('.name', '.id', $where);
                     $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
                     $counties =& CRM_Core_PseudoConstant::county();
                     $value = $counties[(int) $value];
                 } else {
                     $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
                     $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                 }
                 if (!$lType) {
                     $this->_qill[$grouping][] = ts('County') . " {$op} '{$value}'";
                 } else {
                     $this->_qill[$grouping][] = ts('County') . " ({$lType}) {$op} '{$value}'";
                 }
             } else {
                 if ($name === 'world_region') {
                     $worldRegions =& CRM_Core_PseudoConstant::worldRegion();
                     if (is_numeric($value)) {
                         $value = $worldRegions[(int) $value];
                     }
                     $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                     $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                     $this->_qill[$grouping][] = ts('World Region') . " {$op} '{$value}'";
                 } else {
                     if ($name === 'individual_prefix') {
                         $individualPrefixs =& CRM_Core_PseudoConstant::individualPrefix();
                         if (is_numeric($value)) {
                             $value = $individualPrefixs[(int) $value];
                         }
                         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                         $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                         $this->_qill[$grouping][] = ts('Individual Prefix') . " {$op} '{$value}'";
                     } else {
                         if ($name === 'individual_suffix') {
                             $individualSuffixs =& CRM_Core_PseudoConstant::individualsuffix();
                             if (is_numeric($value)) {
                                 $value = $individualSuffixs[(int) $value];
                             }
                             $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                             $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                             $this->_qill[$grouping][] = ts('Individual Suffix') . " {$op} '{$value}'";
                         } else {
                             if ($name === 'gender') {
                                 $genders =& CRM_Core_PseudoConstant::gender();
                                 if (is_numeric($value)) {
                                     $value = $genders[(int) $value];
                                 }
                                 $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                 $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                                 $this->_qill[$grouping][] = ts('Gender') . " {$op} '{$value}'";
                             } else {
                                 if ($name === 'birth_date') {
                                     $date = CRM_Utils_Date::format($value);
                                     $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date);
                                     if ($date) {
                                         $date = CRM_Utils_Date::customFormat($date);
                                         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\"";
                                     } else {
                                         $this->_qill[$grouping][] = "{$field['title']} {$op}";
                                     }
                                 } else {
                                     if ($name === 'deceased_date') {
                                         $date = CRM_Utils_Date::format($value);
                                         $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date);
                                         if ($date) {
                                             $date = CRM_Utils_Date::customFormat($date);
                                             $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\"";
                                         } else {
                                             $this->_qill[$grouping][] = "{$field['title']} {$op}";
                                         }
                                     } else {
                                         if ($name === 'is_deceased') {
                                             $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $value);
                                             $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
                                         } else {
                                             if ($name === 'contact_id') {
                                                 if (is_int($value)) {
                                                     $this->_where[$grouping][] = self::buildClause($field['where'], $op, $value);
                                                     $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}";
                                                 }
                                             } else {
                                                 if ($name === 'name') {
                                                     $value = strtolower(CRM_Core_DAO::escapeString($value));
                                                     if ($wildcard) {
                                                         $value = "%{$value}%";
                                                         $op = 'LIKE';
                                                     }
                                                     $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                                     $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}'");
                                                     $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
                                                 } else {
                                                     if ($name === 'current_employer') {
                                                         $value = strtolower(CRM_Core_DAO::escapeString($value));
                                                         if ($wildcard) {
                                                             $value = "%{$value}%";
                                                             $op = 'LIKE';
                                                         }
                                                         $wc = $op != 'LIKE' ? "LOWER(contact_a.organization_name)" : "contact_a.organization_name";
                                                         $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}' AND contact_a.contact_type ='Individual'");
                                                         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
                                                     } else {
                                                         if ($name === 'email_greeting') {
                                                             $filterCondition = array('greeting_type' => 'email_greeting');
                                                             $emailGreetings =& CRM_Core_PseudoConstant::greeting($filterCondition);
                                                             if (is_numeric($value)) {
                                                                 $value = $emailGreetings[(int) $value];
                                                             }
                                                             $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                                             $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                                                             $this->_qill[$grouping][] = ts('Email Greeting') . " {$op} '{$value}'";
                                                         } else {
                                                             if ($name === 'postal_greeting') {
                                                                 $filterCondition = array('greeting_type' => 'postal_greeting');
                                                                 $postalGreetings =& CRM_Core_PseudoConstant::greeting($filterCondition);
                                                                 if (is_numeric($value)) {
                                                                     $value = $postalGreetings[(int) $value];
                                                                 }
                                                                 $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                                                 $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                                                                 $this->_qill[$grouping][] = ts('Postal Greeting') . " {$op} '{$value}'";
                                                             } else {
                                                                 if ($name === 'addressee') {
                                                                     $filterCondition = array('greeting_type' => 'addressee');
                                                                     $addressee =& CRM_Core_PseudoConstant::greeting($filterCondition);
                                                                     if (is_numeric($value)) {
                                                                         $value = $addressee[(int) $value];
                                                                     }
                                                                     $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                                                     $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                                                                     $this->_qill[$grouping][] = ts('Addressee') . " {$op} '{$value}'";
                                                                 } else {
                                                                     // sometime the value is an array, need to investigate and fix
                                                                     if (is_array($value)) {
                                                                         CRM_Core_Error::fatal();
                                                                     }
                                                                     if (!empty($field['where'])) {
                                                                         if ($op != 'IN') {
                                                                             $value = strtolower(CRM_Core_DAO::escapeString($value));
                                                                         }
                                                                         if ($wildcard) {
                                                                             $value = "%{$value}%";
                                                                             $op = 'LIKE';
                                                                         }
                                                                         if ($op != 'IN') {
                                                                             $value = "'{$value}'";
                                                                         }
                                                                         if (isset($locType[1]) && is_numeric($locType[1])) {
                                                                             $setTables = false;
                                                                             //get the location name
                                                                             $locationType =& CRM_Core_PseudoConstant::locationType();
                                                                             list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
                                                                             $where = "`{$tName}`.{$fldName}";
                                                                             $this->_where[$grouping][] = self::buildClause("LOWER({$where})", $op, $value);
                                                                             $this->_whereTables[$tName] = $this->_tables[$tName];
                                                                             $this->_qill[$grouping][] = "{$field['title']} {$op} '{$value}'";
                                                                         } else {
                                                                             list($tableName, $fieldName) = explode('.', $field['where'], 2);
                                                                             if ($tableName == 'civicrm_contact') {
                                                                                 $fieldName = "LOWER(contact_a.{$fieldName})";
                                                                             } else {
                                                                                 if ($op != 'IN' && !is_numeric($value)) {
                                                                                     $fieldName = "LOWER({$field['where']})";
                                                                                 } else {
                                                                                     $fieldName = "{$field['where']}";
                                                                                 }
                                                                             }
                                                                             $this->_where[$grouping][] = self::buildClause($fieldName, $op, $value);
                                                                             $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}";
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($setTables) {
         list($tableName, $fieldName) = explode('.', $field['where'], 2);
         if (isset($tableName)) {
             $this->_tables[$tableName] = 1;
             $this->_whereTables[$tableName] = 1;
         }
     }
 }
コード例 #14
0
ファイル: Contact.php プロジェクト: ryanrd/DW-Campaigns
/**
 * Validate the addressee or email or postal greetings 
 *
 * @param  $params                   Associative array of property name/value
 *                                   pairs to insert in new contact.
 * 
 * @return array (reference )        null on success, error message otherwise
 *
 * @access public
 */
function _civicrm_greeting_format_params( &$params ) 
{
    $greetingParams = array( '', '_id', '_custom' );
    foreach ( array( 'email', 'postal', 'addressee' ) as $key ) {
        $greeting = '_greeting';
        if ( $key == 'addressee' ) {
            $greeting = '';   
        } 

        $formatParams = false;
        // unset display value from params.
        if ( isset( $params["{$key}{$greeting}_display"] ) ) {
            unset( $params["{$key}{$greeting}_display"] );  
        }

        // check if greetings are present in present
        foreach ( $greetingParams as $greetingValues ) {
            if ( array_key_exists( "{$key}{$greeting}{$greetingValues}", $params ) ) {
                $formatParams = true;
                break;
            }
        }

        if ( !$formatParams ) continue;
    
        // format params
        if ( CRM_Utils_Array::value( 'contact_type', $params ) == 'Organization' && $key != 'addressee' ) {
            return civicrm_create_error( ts( 'You cannot use email/postal greetings for contact type %1.', 
                                             array( 1 => $params['contact_type'] ) ) );
        }
        
        $nullValue      = false; 
        $filter         = array( 'contact_type'  => $params['contact_type'],
                                 'greeting_type' => "{$key}{$greeting}" );
        
        $greetings      = CRM_Core_PseudoConstant::greeting( $filter );
        $greetingId     = CRM_Utils_Array::value( "{$key}{$greeting}_id",     $params );
        $greetingVal    = CRM_Utils_Array::value( "{$key}{$greeting}",        $params );
        $customGreeting = CRM_Utils_Array::value( "{$key}{$greeting}_custom", $params );
        
        if ( !$greetingId && $greetingVal ) {
            $params["{$key}{$greeting}_id"] = CRM_Utils_Array::key( $params["{$key}{$greeting}"], $greetings );
        }
        
        if ( $customGreeting && $greetingId &&
             ( $greetingId != array_search( 'Customized', $greetings ) ) ) {
            return civicrm_create_error( ts( 'Provide either %1 greeting id and/or %1 greeting or custom %1 greeting',
                                             array( 1 => $key ) ) );
        }
        
        if ( $greetingVal && $greetingId &&
             ( $greetingId != CRM_Utils_Array::key( $greetingVal, $greetings ) ) ) {
            return civicrm_create_error( ts( 'Mismatch in %1 greeting id and %1 greeting',
                                             array( 1 => $key ) ) );
        } 
        
        if ( $greetingId ) {

            if ( !array_key_exists( $greetingId, $greetings ) ) {
                return civicrm_create_error( ts( 'Invalid %1 greeting Id', array( 1 => $key ) ) );
            }
            
            if ( !$customGreeting && ( $greetingId == array_search( 'Customized', $greetings ) ) ) {
                return civicrm_create_error( ts( 'Please provide a custom value for %1 greeting', 
                                                 array( 1 => $key ) ) );
            }
                        
        } else if ( $greetingVal ) {

            if ( !in_array( $greetingVal, $greetings ) ) {
                return civicrm_create_error( ts( 'Invalid %1 greeting', array( 1 => $key ) ) );
            }

            $greetingId = CRM_Utils_Array::key( $greetingVal, $greetings );
        }
                     
        if ( $customGreeting ) {
            $greetingId = CRM_Utils_Array::key( 'Customized', $greetings );
        }

        $customValue = $params['contact_id'] ? CRM_Core_DAO::getFieldValue( 'CRM_Contact_DAO_Contact', 
                                                                            $params['contact_id'], 
                                                                            "{$key}{$greeting}_custom" ) : false;
                
        if ( array_key_exists( "{$key}{$greeting}_id", $params ) && empty( $params["{$key}{$greeting}_id"] ) ) {
            $nullValue = true;
        } else if ( array_key_exists( "{$key}{$greeting}", $params ) && empty( $params["{$key}{$greeting}"] ) ) {
            $nullValue = true;
        } else if ( $customValue && array_key_exists( "{$key}{$greeting}_custom", $params ) 
                    && empty( $params["{$key}{$greeting}_custom"] ) ) {
            $nullValue = true;
        }

        $params["{$key}{$greeting}_id"] = $greetingId;

        if ( !$customValue && !$customGreeting && array_key_exists( "{$key}{$greeting}_custom", $params ) ) {
            unset( $params["{$key}{$greeting}_custom"] );
        }
        
        if ( $nullValue ) {
            $params["{$key}{$greeting}_id"]     = '';
            $params["{$key}{$greeting}_custom"] = '';
        }
                                
        if ( isset( $params["{$key}{$greeting}"] ) ) {
            unset( $params["{$key}{$greeting}"] );
        }
    }
}
コード例 #15
0
 /**
  * Process greetings and cache.
  *
  * @param object $contact
  *   Contact object after save.
  * @param bool $useDefaults
  *   Use default greeting values.
  */
 public static function processGreetings(&$contact, $useDefaults = FALSE)
 {
     if ($useDefaults) {
         //retrieve default greetings
         $defaultGreetings = CRM_Core_PseudoConstant::greetingDefaults();
         $contactDefaults = $defaultGreetings[$contact->contact_type];
     }
     // note that contact object not always has required greeting related
     // fields that are required to calculate greeting and
     // also other fields used in tokens etc,
     // hence we need to retrieve it again.
     if ($contact->_query !== FALSE) {
         $contact->find(TRUE);
     }
     // store object values to an array
     $contactDetails = array();
     CRM_Core_DAO::storeValues($contact, $contactDetails);
     $contactDetails = array(array($contact->id => $contactDetails));
     $emailGreetingString = $postalGreetingString = $addresseeString = NULL;
     $updateQueryString = array();
     //cache email and postal greeting to greeting display
     if ($contact->email_greeting_custom != 'null' && $contact->email_greeting_custom) {
         $emailGreetingString = $contact->email_greeting_custom;
     } elseif ($contact->email_greeting_id != 'null' && $contact->email_greeting_id) {
         // the filter value for Individual contact type is set to 1
         $filter = array('contact_type' => $contact->contact_type, 'greeting_type' => 'email_greeting');
         $emailGreeting = CRM_Core_PseudoConstant::greeting($filter);
         $emailGreetingString = $emailGreeting[$contact->email_greeting_id];
         $updateQueryString[] = " email_greeting_custom = NULL ";
     } else {
         if ($useDefaults) {
             reset($contactDefaults['email_greeting']);
             $emailGreetingID = key($contactDefaults['email_greeting']);
             $emailGreetingString = $contactDefaults['email_greeting'][$emailGreetingID];
             $updateQueryString[] = " email_greeting_id = {$emailGreetingID} ";
             $updateQueryString[] = " email_greeting_custom = NULL ";
         } elseif ($contact->email_greeting_custom) {
             $updateQueryString[] = " email_greeting_display = NULL ";
         }
     }
     if ($emailGreetingString) {
         CRM_Contact_BAO_Contact_Utils::processGreetingTemplate($emailGreetingString, $contactDetails, $contact->id, 'CRM_Contact_BAO_Contact');
         $emailGreetingString = CRM_Core_DAO::escapeString(CRM_Utils_String::stripSpaces($emailGreetingString));
         $updateQueryString[] = " email_greeting_display = '{$emailGreetingString}'";
     }
     //postal greetings
     if ($contact->postal_greeting_custom != 'null' && $contact->postal_greeting_custom) {
         $postalGreetingString = $contact->postal_greeting_custom;
     } elseif ($contact->postal_greeting_id != 'null' && $contact->postal_greeting_id) {
         $filter = array('contact_type' => $contact->contact_type, 'greeting_type' => 'postal_greeting');
         $postalGreeting = CRM_Core_PseudoConstant::greeting($filter);
         $postalGreetingString = $postalGreeting[$contact->postal_greeting_id];
         $updateQueryString[] = " postal_greeting_custom = NULL ";
     } else {
         if ($useDefaults) {
             reset($contactDefaults['postal_greeting']);
             $postalGreetingID = key($contactDefaults['postal_greeting']);
             $postalGreetingString = $contactDefaults['postal_greeting'][$postalGreetingID];
             $updateQueryString[] = " postal_greeting_id = {$postalGreetingID} ";
             $updateQueryString[] = " postal_greeting_custom = NULL ";
         } elseif ($contact->postal_greeting_custom) {
             $updateQueryString[] = " postal_greeting_display = NULL ";
         }
     }
     if ($postalGreetingString) {
         CRM_Contact_BAO_Contact_Utils::processGreetingTemplate($postalGreetingString, $contactDetails, $contact->id, 'CRM_Contact_BAO_Contact');
         $postalGreetingString = CRM_Core_DAO::escapeString(CRM_Utils_String::stripSpaces($postalGreetingString));
         $updateQueryString[] = " postal_greeting_display = '{$postalGreetingString}'";
     }
     // addressee
     if ($contact->addressee_custom != 'null' && $contact->addressee_custom) {
         $addresseeString = $contact->addressee_custom;
     } elseif ($contact->addressee_id != 'null' && $contact->addressee_id) {
         $filter = array('contact_type' => $contact->contact_type, 'greeting_type' => 'addressee');
         $addressee = CRM_Core_PseudoConstant::greeting($filter);
         $addresseeString = $addressee[$contact->addressee_id];
         $updateQueryString[] = " addressee_custom = NULL ";
     } else {
         if ($useDefaults) {
             reset($contactDefaults['addressee']);
             $addresseeID = key($contactDefaults['addressee']);
             $addresseeString = $contactDefaults['addressee'][$addresseeID];
             $updateQueryString[] = " addressee_id = {$addresseeID} ";
             $updateQueryString[] = " addressee_custom = NULL ";
         } elseif ($contact->addressee_custom) {
             $updateQueryString[] = " addressee_display = NULL ";
         }
     }
     if ($addresseeString) {
         CRM_Contact_BAO_Contact_Utils::processGreetingTemplate($addresseeString, $contactDetails, $contact->id, 'CRM_Contact_BAO_Contact');
         $addresseeString = CRM_Core_DAO::escapeString(CRM_Utils_String::stripSpaces($addresseeString));
         $updateQueryString[] = " addressee_display = '{$addresseeString}'";
     }
     if (!empty($updateQueryString)) {
         $updateQueryString = implode(',', $updateQueryString);
         $queryString = "UPDATE civicrm_contact SET {$updateQueryString} WHERE id = {$contact->id}";
         CRM_Core_DAO::executeQuery($queryString);
     }
 }
コード例 #16
0
ファイル: Query.php プロジェクト: ruchirapingale/civicrm-core
 /**
  * @param $values
  *
  * @throws Exception
  */
 function restWhere(&$values)
 {
     $name = CRM_Utils_Array::value(0, $values);
     $op = CRM_Utils_Array::value(1, $values);
     $value = CRM_Utils_Array::value(2, $values);
     $grouping = CRM_Utils_Array::value(3, $values);
     $wildcard = CRM_Utils_Array::value(4, $values);
     if (isset($grouping) && empty($this->_where[$grouping])) {
         $this->_where[$grouping] = array();
     }
     $multipleFields = array('url');
     //check if the location type exits for fields
     $lType = '';
     $locType = explode('-', $name);
     if (!in_array($locType[0], $multipleFields)) {
         //add phone type if exists
         if (isset($locType[2]) && $locType[2]) {
             $locType[2] = CRM_Core_DAO::escapeString($locType[2]);
         }
     }
     $field = CRM_Utils_Array::value($name, $this->_fields);
     if (!$field) {
         $field = CRM_Utils_Array::value($locType[0], $this->_fields);
         if (!$field) {
             return;
         }
     }
     $setTables = TRUE;
     $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
     $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     if (substr($name, 0, 14) === 'state_province') {
         if (isset($locType[1]) && is_numeric($locType[1])) {
             $setTables = FALSE;
             $aName = "{$locationType[$locType[1]]}-address";
             $where = "`{$aName}`.state_province_id";
         } else {
             $where = "civicrm_address.state_province_id";
         }
         $states = CRM_Core_PseudoConstant::stateProvince();
         if (is_numeric($value)) {
             $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
             $value = $states[(int) $value];
         } else {
             $intVal = CRM_Utils_Array::key($value, $states);
             $this->_where[$grouping][] = self::buildClause($where, $op, $intVal, 'Positive');
         }
         if (!$lType) {
             $this->_qill[$grouping][] = ts('State') . " {$op} '{$value}'";
         } else {
             $this->_qill[$grouping][] = ts('State') . " ({$lType}) {$op} '{$value}'";
         }
     } elseif (!empty($field['pseudoconstant'])) {
         $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', $field['name']), $field, $field['title'], 'String', TRUE);
         if ($name == 'gender_id') {
             self::$_openedPanes[ts('Demographics')] = TRUE;
         }
     } elseif (substr($name, 0, 7) === 'country') {
         if (isset($locType[1]) && is_numeric($locType[1])) {
             $setTables = FALSE;
             $aName = "{$locationType[$locType[1]]}-address";
             $where = "`{$aName}`.country_id";
         } else {
             $where = "civicrm_address.country_id";
         }
         $countries = CRM_Core_PseudoConstant::country();
         if (is_numeric($value)) {
             $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
             $value = $countries[(int) $value];
         } else {
             $intVal = CRM_Utils_Array::key($value, $countries);
             $this->_where[$grouping][] = self::buildClause($where, $op, $intVal, 'Positive');
         }
         if (!$lType) {
             $this->_qill[$grouping][] = ts('Country') . " {$op} '{$value}'";
         } else {
             $this->_qill[$grouping][] = ts('Country') . " ({$lType}) {$op} '{$value}'";
         }
     } elseif (substr($name, 0, 6) === 'county') {
         if (isset($locType[1]) && is_numeric($locType[1])) {
             $setTables = FALSE;
             $aName = "{$locationType[$locType[1]]}-address";
             $where = "`{$aName}`.county_id";
         } else {
             $where = "civicrm_address.county_id";
         }
         $counties = CRM_Core_PseudoConstant::county();
         if (is_numeric($value)) {
             $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
             $value = $counties[(int) $value];
         } else {
             $intVal = CRM_Utils_Array::key($value, $counties);
             $this->_where[$grouping][] = self::buildClause($where, $op, $intVal, 'Positive');
         }
         if (!$lType) {
             $this->_qill[$grouping][] = ts('County') . " {$op} '{$value}'";
         } else {
             $this->_qill[$grouping][] = ts('County') . " ({$lType}) {$op} '{$value}'";
         }
     } elseif ($name === 'world_region') {
         $field['where'] = 'civicrm_worldregion.id';
         $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::worldRegion(), $field, ts('World Region'), 'Positive', TRUE);
     } elseif ($name === 'birth_date') {
         $date = CRM_Utils_Date::processDate($value);
         $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date);
         if ($date) {
             $date = CRM_Utils_Date::customFormat($date);
             $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\"";
         } else {
             $this->_qill[$grouping][] = "{$field['title']} {$op}";
         }
         self::$_openedPanes[ts('Demographics')] = TRUE;
     } elseif ($name === 'deceased_date') {
         $date = CRM_Utils_Date::processDate($value);
         $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date);
         if ($date) {
             $date = CRM_Utils_Date::customFormat($date);
             $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\"";
         } else {
             $this->_qill[$grouping][] = "{$field['title']} {$op}";
         }
         self::$_openedPanes[ts('Demographics')] = TRUE;
     } elseif ($name === 'is_deceased') {
         $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $value);
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
         self::$_openedPanes[ts('Demographics')] = TRUE;
     } elseif ($name === 'contact_id') {
         if (is_int($value)) {
             $this->_where[$grouping][] = self::buildClause($field['where'], $op, $value);
             $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}";
         }
     } elseif ($name === 'name') {
         $value = $strtolower(CRM_Core_DAO::escapeString($value));
         if ($wildcard) {
             $value = "%{$value}%";
             $op = 'LIKE';
         }
         $wc = self::caseImportant($op) ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}'");
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } elseif ($name === 'current_employer') {
         $value = $strtolower(CRM_Core_DAO::escapeString($value));
         if ($wildcard) {
             $value = "%{$value}%";
             $op = 'LIKE';
         }
         $wc = self::caseImportant($op) ? "LOWER(contact_a.organization_name)" : "contact_a.organization_name";
         $ceWhereClause = self::buildClause($wc, $op, $value);
         $ceWhereClause .= " AND contact_a.contact_type = 'Individual'";
         $this->_where[$grouping][] = $ceWhereClause;
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } elseif ($name === 'email_greeting') {
         $filterCondition = array('greeting_type' => 'email_greeting');
         $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Email Greeting'));
     } elseif ($name === 'postal_greeting') {
         $filterCondition = array('greeting_type' => 'postal_greeting');
         $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Postal Greeting'));
     } elseif ($name === 'addressee') {
         $filterCondition = array('greeting_type' => 'addressee');
         $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Addressee'));
     } elseif (substr($name, 0, 4) === 'url-') {
         $tName = 'civicrm_website';
         $this->_whereTables[$tName] = $this->_tables[$tName] = "\nLEFT JOIN civicrm_website ON ( civicrm_website.contact_id = contact_a.id )";
         $value = $strtolower(CRM_Core_DAO::escapeString($value));
         if ($wildcard) {
             $value = "%{$value}%";
             $op = 'LIKE';
         }
         $wc = 'civicrm_website.url';
         $this->_where[$grouping][] = $d = self::buildClause($wc, $op, $value);
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } elseif ($name === 'contact_is_deleted') {
         $this->_where[$grouping][] = self::buildClause("contact_a.is_deleted", $op, $value);
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } else {
         if (is_array($value)) {
             // traditionally an array being passed has been a fatal error. We can take advantage of this to add support
             // for api style operators for functions that hit this point without worrying about regression
             // (the previous comments indicated the condition for hitting this point were unknown
             // per CRM-14743 we are adding modified_date & created_date operator support
             $operations = array_keys($value);
             foreach ($operations as $operator) {
                 if (!in_array($operator, CRM_Core_DAO::acceptedSQLOperators())) {
                     // we don't know when this might happen
                     CRM_Core_Error::fatal();
                 }
             }
             $this->_where[$grouping][] = CRM_Core_DAO::createSQLFilter($name, $value, NULL);
             //since this is not currently being called by the form layer we can skip worrying about the 'qill' for now
             return;
         }
         if (!empty($field['where'])) {
             if ($op != 'IN') {
                 $value = $strtolower($value);
             }
             if ($wildcard) {
                 $value = "%{$value}%";
                 $op = 'LIKE';
             }
             if (isset($locType[1]) && is_numeric($locType[1])) {
                 $setTables = FALSE;
                 //get the location name
                 list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
                 $where = "`{$tName}`.{$fldName}";
                 $this->_where[$grouping][] = self::buildClause("LOWER({$where})", $op, $value);
                 // we set both _tables & whereTables because whereTables doesn't seem to do what the name implies it should
                 $this->_tables[$tName] = $this->_whereTables[$tName] = 1;
                 $this->_qill[$grouping][] = "{$field['title']} {$op} '{$value}'";
             } else {
                 list($tableName, $fieldName) = explode('.', $field['where'], 2);
                 if ($tableName == 'civicrm_contact') {
                     $fieldName = "LOWER(contact_a.{$fieldName})";
                 } else {
                     if ($op != 'IN' && !is_numeric($value)) {
                         $fieldName = "LOWER({$field['where']})";
                     } else {
                         $fieldName = "{$field['where']}";
                     }
                 }
                 $type = NULL;
                 if (!empty($field['type'])) {
                     $type = CRM_Utils_Type::typeToString($field['type']);
                 }
                 $this->_where[$grouping][] = self::buildClause($fieldName, $op, $value, $type);
                 $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}";
             }
         }
     }
     if ($setTables && isset($field['where'])) {
         list($tableName, $fieldName) = explode('.', $field['where'], 2);
         if (isset($tableName)) {
             $this->_tables[$tableName] = 1;
             $this->_whereTables[$tableName] = 1;
         }
     }
 }
コード例 #17
0
ファイル: Query.php プロジェクト: hoegrammer/civicrm-core
 /**
  * Generate where clause for any parameters not already handled.
  *
  * @param array $values
  *
  * @throws Exception
  */
 public function restWhere(&$values)
 {
     $name = CRM_Utils_Array::value(0, $values);
     $op = CRM_Utils_Array::value(1, $values);
     $value = CRM_Utils_Array::value(2, $values);
     $grouping = CRM_Utils_Array::value(3, $values);
     $wildcard = CRM_Utils_Array::value(4, $values);
     if (isset($grouping) && empty($this->_where[$grouping])) {
         $this->_where[$grouping] = array();
     }
     $multipleFields = array('url');
     //check if the location type exits for fields
     $lType = '';
     $locType = explode('-', $name);
     if (!in_array($locType[0], $multipleFields)) {
         //add phone type if exists
         if (isset($locType[2]) && $locType[2]) {
             $locType[2] = CRM_Core_DAO::escapeString($locType[2]);
         }
     }
     $field = CRM_Utils_Array::value($name, $this->_fields);
     if (!$field) {
         $field = CRM_Utils_Array::value($locType[0], $this->_fields);
         if (!$field) {
             return;
         }
     }
     $setTables = TRUE;
     $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
     $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     if (substr($name, 0, 14) === 'state_province') {
         if (isset($locType[1]) && is_numeric($locType[1])) {
             $setTables = FALSE;
             $aName = "{$locationType[$locType[1]]}-address";
             $where = "`{$aName}`.state_province_id";
         } else {
             $where = "civicrm_address.state_province_id";
         }
         $this->_where[$grouping][] = self::buildClause($where, $op, $value);
         list($qillop, $qillVal) = self::buildQillForFieldValue('CRM_Core_DAO_Address', "state_province_id", $value, $op);
         $this->_qill[$grouping][] = ts("State %1 %2", array(1 => $qillop, 2 => $qillVal));
     } elseif (!empty($field['pseudoconstant'])) {
         $this->optionValueQuery($name, $op, $value, $grouping, 'CRM_Contact_DAO_Contact', $field, $field['title'], 'String', TRUE);
         if ($name == 'gender_id') {
             self::$_openedPanes[ts('Demographics')] = TRUE;
         }
     } elseif (substr($name, 0, 7) === 'country' || substr($name, 0, 6) === 'county') {
         $name = substr($name, 0, 7) === 'country' ? "country_id" : "county_id";
         if (isset($locType[1]) && is_numeric($locType[1])) {
             $setTables = FALSE;
             $aName = "{$locationType[$locType[1]]}-address";
             $where = "`{$aName}`.{$name}";
         } else {
             $where = "civicrm_address.{$name}";
         }
         $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
         if ($lType) {
             $field['title'] .= " ({$lType})";
         }
         list($qillop, $qillVal) = CRM_Contact_BAO_Query::buildQillForFieldValue(NULL, $name, $value, $op);
         $this->_qill[$grouping][] = ts("%1 %2 %3", array(1 => $field['title'], 2 => $qillop, 3 => $qillVal));
     } elseif ($name === 'world_region') {
         $this->optionValueQuery($name, $op, $value, $grouping, NULL, $field, ts('World Region'), 'Positive', TRUE);
     } elseif ($name === 'is_deceased') {
         $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $value);
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
         self::$_openedPanes[ts('Demographics')] = TRUE;
     } elseif ($name === 'created_date' || $name === 'modified_date' || $name === 'deceased_date' || $name === 'birth_date') {
         $appendDateTime = TRUE;
         if ($name === 'deceased_date' || $name === 'birth_date') {
             $appendDateTime = FALSE;
             self::$_openedPanes[ts('Demographics')] = TRUE;
         }
         $this->dateQueryBuilder($values, 'contact_a', $name, $name, $field['title'], $appendDateTime);
     } elseif ($name === 'contact_id') {
         if (is_int($value)) {
             $this->_where[$grouping][] = self::buildClause($field['where'], $op, $value);
             $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}";
         }
     } elseif ($name === 'name') {
         $value = $strtolower(CRM_Core_DAO::escapeString($value));
         if ($wildcard) {
             $value = "%{$value}%";
             $op = 'LIKE';
         }
         $wc = self::caseImportant($op) ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}'");
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } elseif ($name === 'current_employer') {
         $value = $strtolower(CRM_Core_DAO::escapeString($value));
         if ($wildcard) {
             $value = "%{$value}%";
             $op = 'LIKE';
         }
         $wc = self::caseImportant($op) ? "LOWER(contact_a.organization_name)" : "contact_a.organization_name";
         $ceWhereClause = self::buildClause($wc, $op, $value);
         $ceWhereClause .= " AND contact_a.contact_type = 'Individual'";
         $this->_where[$grouping][] = $ceWhereClause;
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } elseif ($name === 'email_greeting') {
         $filterCondition = array('greeting_type' => 'email_greeting');
         $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Email Greeting'));
     } elseif ($name === 'postal_greeting') {
         $filterCondition = array('greeting_type' => 'postal_greeting');
         $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Postal Greeting'));
     } elseif ($name === 'addressee') {
         $filterCondition = array('greeting_type' => 'addressee');
         $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Addressee'));
     } elseif (substr($name, 0, 4) === 'url-') {
         $tName = 'civicrm_website';
         $this->_whereTables[$tName] = $this->_tables[$tName] = "\nLEFT JOIN civicrm_website ON ( civicrm_website.contact_id = contact_a.id )";
         $value = $strtolower(CRM_Core_DAO::escapeString($value));
         if ($wildcard) {
             $value = "%{$value}%";
             $op = 'LIKE';
         }
         $wc = 'civicrm_website.url';
         $this->_where[$grouping][] = $d = self::buildClause($wc, $op, $value);
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } elseif ($name === 'contact_is_deleted') {
         $this->_where[$grouping][] = self::buildClause("contact_a.is_deleted", $op, $value);
         list($qillop, $qillVal) = CRM_Contact_BAO_Query::buildQillForFieldValue(NULL, $name, $value, $op);
         $this->_qill[$grouping][] = ts("%1 %2 %3", array(1 => $field['title'], 2 => $qillop, 3 => $qillVal));
     } elseif (!empty($field['where'])) {
         $type = NULL;
         if (!empty($field['type'])) {
             $type = CRM_Utils_Type::typeToString($field['type']);
         }
         list($tableName, $fieldName) = explode('.', $field['where'], 2);
         if (isset($locType[1]) && is_numeric($locType[1])) {
             $setTables = FALSE;
             //get the location name
             list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
             $fieldName = "LOWER(`{$tName}`.{$fldName})";
             // we set both _tables & whereTables because whereTables doesn't seem to do what the name implies it should
             $this->_tables[$tName] = $this->_whereTables[$tName] = 1;
         } else {
             if ($tableName == 'civicrm_contact') {
                 $fieldName = "LOWER(contact_a.{$fieldName})";
             } else {
                 if ($op != 'IN' && !is_numeric($value)) {
                     $fieldName = "LOWER({$field['where']})";
                 } else {
                     $fieldName = "{$field['where']}";
                 }
             }
         }
         list($qillop, $qillVal) = self::buildQillForFieldValue(NULL, $field['title'], $value, $op);
         $this->_qill[$grouping][] = ts("%1 %2 %3", array(1 => $field['title'], 2 => $qillop, 3 => strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE ? $qillVal : "'{$qillVal}'"));
         if (is_array($value)) {
             // traditionally an array being passed has been a fatal error. We can take advantage of this to add support
             // for api style operators for functions that hit this point without worrying about regression
             // (the previous comments indicated the condition for hitting this point were unknown
             // per CRM-14743 we are adding modified_date & created_date operator support
             $operations = array_keys($value);
             foreach ($operations as $operator) {
                 if (!in_array($operator, CRM_Core_DAO::acceptedSQLOperators())) {
                     //Via Contact get api value is not in array(operator => array(values)) format ONLY for IN/NOT IN operators
                     //so this condition will satisfy the search for now
                     if (strpos($op, 'IN') !== FALSE) {
                         $value = array($op => $value);
                     } else {
                         CRM_Core_Error::fatal(ts("%1 is not a valid operator", array(1 => $operator)));
                     }
                 }
             }
             $this->_where[$grouping][] = CRM_Core_DAO::createSQLFilter($fieldName, $value, $type);
         } else {
             if (!strpos($op, 'IN')) {
                 $value = $strtolower($value);
             }
             if ($wildcard) {
                 $value = "%{$value}%";
                 $op = 'LIKE';
             }
             $this->_where[$grouping][] = self::buildClause($fieldName, $op, $value, $type);
         }
     }
     if ($setTables && isset($field['where'])) {
         list($tableName, $fieldName) = explode('.', $field['where'], 2);
         if (isset($tableName)) {
             $this->_tables[$tableName] = 1;
             $this->_whereTables[$tableName] = 1;
         }
     }
 }
コード例 #18
0
ファイル: Contact.php プロジェクト: nielosz/civicrm-core
/**
 * Validate the addressee or email or postal greetings.
 *
 * @param array $params
 *   Array per getfields metadata.
 *
 * @throws API_Exception
 */
function _civicrm_api3_greeting_format_params($params)
{
    $greetingParams = array('', '_id', '_custom');
    foreach (array('email', 'postal', 'addressee') as $key) {
        $greeting = '_greeting';
        if ($key == 'addressee') {
            $greeting = '';
        }
        $formatParams = FALSE;
        // Unset display value from params.
        if (isset($params["{$key}{$greeting}_display"])) {
            unset($params["{$key}{$greeting}_display"]);
        }
        // check if greetings are present in present
        foreach ($greetingParams as $greetingValues) {
            if (array_key_exists("{$key}{$greeting}{$greetingValues}", $params)) {
                $formatParams = TRUE;
                break;
            }
        }
        if (!$formatParams) {
            continue;
        }
        $nullValue = FALSE;
        $filter = array('contact_type' => $params['contact_type'], 'greeting_type' => "{$key}{$greeting}");
        $greetings = CRM_Core_PseudoConstant::greeting($filter);
        $greetingId = CRM_Utils_Array::value("{$key}{$greeting}_id", $params);
        $greetingVal = CRM_Utils_Array::value("{$key}{$greeting}", $params);
        $customGreeting = CRM_Utils_Array::value("{$key}{$greeting}_custom", $params);
        if (!$greetingId && $greetingVal) {
            $params["{$key}{$greeting}_id"] = CRM_Utils_Array::key($params["{$key}{$greeting}"], $greetings);
        }
        if ($customGreeting && $greetingId && $greetingId != array_search('Customized', $greetings)) {
            throw new API_Exception(ts('Provide either %1 greeting id and/or %1 greeting or custom %1 greeting', array(1 => $key)));
        }
        if ($greetingVal && $greetingId && $greetingId != CRM_Utils_Array::key($greetingVal, $greetings)) {
            throw new API_Exception(ts('Mismatch in %1 greeting id and %1 greeting', array(1 => $key)));
        }
        if ($greetingId) {
            if (!array_key_exists($greetingId, $greetings)) {
                throw new API_Exception(ts('Invalid %1 greeting Id', array(1 => $key)));
            }
            if (!$customGreeting && $greetingId == array_search('Customized', $greetings)) {
                throw new API_Exception(ts('Please provide a custom value for %1 greeting', array(1 => $key)));
            }
        } elseif ($greetingVal) {
            if (!in_array($greetingVal, $greetings)) {
                throw new API_Exception(ts('Invalid %1 greeting', array(1 => $key)));
            }
            $greetingId = CRM_Utils_Array::key($greetingVal, $greetings);
        }
        if ($customGreeting) {
            $greetingId = CRM_Utils_Array::key('Customized', $greetings);
        }
        $customValue = isset($params['contact_id']) ? CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $params['contact_id'], "{$key}{$greeting}_custom") : FALSE;
        if (array_key_exists("{$key}{$greeting}_id", $params) && empty($params["{$key}{$greeting}_id"])) {
            $nullValue = TRUE;
        } elseif (array_key_exists("{$key}{$greeting}", $params) && empty($params["{$key}{$greeting}"])) {
            $nullValue = TRUE;
        } elseif ($customValue && array_key_exists("{$key}{$greeting}_custom", $params) && empty($params["{$key}{$greeting}_custom"])) {
            $nullValue = TRUE;
        }
        $params["{$key}{$greeting}_id"] = $greetingId;
        if (!$customValue && !$customGreeting && array_key_exists("{$key}{$greeting}_custom", $params)) {
            unset($params["{$key}{$greeting}_custom"]);
        }
        if ($nullValue) {
            $params["{$key}{$greeting}_id"] = '';
            $params["{$key}{$greeting}_custom"] = '';
        }
        if (isset($params["{$key}{$greeting}"])) {
            unset($params["{$key}{$greeting}"]);
        }
    }
}
コード例 #19
0
ファイル: Utils.php プロジェクト: FundingWorks/civicrm-core
 /**
  * @param array $params
  *
  * @throws Exception
  */
 public static function updateGreeting($params)
 {
     $contactType = $params['ct'];
     $greeting = $params['gt'];
     $valueID = $id = CRM_Utils_Array::value('id', $params);
     $force = CRM_Utils_Array::value('force', $params);
     $limit = CRM_Utils_Array::value('limit', $params);
     // if valueID is not passed use default value
     if (!$valueID) {
         $valueID = $id = self::defaultGreeting($contactType, $greeting);
     }
     $filter = array('contact_type' => $contactType, 'greeting_type' => $greeting);
     $allGreetings = CRM_Core_PseudoConstant::greeting($filter);
     $originalGreetingString = $greetingString = CRM_Utils_Array::value($valueID, $allGreetings);
     if (!$greetingString) {
         CRM_Core_Error::fatal(ts('Incorrect greeting value id %1, or no default greeting for this contact type and greeting type.', array(1 => $valueID)));
     }
     // build return properties based on tokens
     $greetingTokens = CRM_Utils_Token::getTokens($greetingString);
     $tokens = CRM_Utils_Array::value('contact', $greetingTokens);
     $greetingsReturnProperties = array();
     if (is_array($tokens)) {
         $greetingsReturnProperties = array_fill_keys(array_values($tokens), 1);
     }
     // Process ALL contacts only when force=1 or force=2 is passed. Else only contacts with NULL greeting or addressee value are updated.
     $processAll = $processOnlyIdSet = FALSE;
     if ($force == 1) {
         $processAll = TRUE;
     } elseif ($force == 2) {
         $processOnlyIdSet = TRUE;
     }
     //FIXME : apiQuery should handle these clause.
     $filterContactFldIds = $filterIds = array();
     $idFldName = $displayFldName = NULL;
     if (in_array($greeting, CRM_Contact_BAO_Contact::$_greetingTypes)) {
         $idFldName = $greeting . '_id';
         $displayFldName = $greeting . '_display';
     }
     if ($idFldName) {
         $queryParams = array(1 => array($contactType, 'String'));
         // if $force == 1 then update all contacts else only
         // those with NULL greeting or addressee value CRM-9476
         if ($processAll) {
             $sql = "SELECT DISTINCT id, {$idFldName} FROM civicrm_contact WHERE contact_type = %1 ";
         } else {
             $sql = "\n          SELECT DISTINCT id, {$idFldName}\n          FROM civicrm_contact\n          WHERE contact_type = %1\n          AND ({$idFldName} IS NULL\n          OR ( {$idFldName} IS NOT NULL AND ({$displayFldName} IS NULL OR {$displayFldName} = '')) )";
         }
         if ($limit) {
             $sql .= " LIMIT 0, %2";
             $queryParams += array(2 => array($limit, 'Integer'));
         }
         $dao = CRM_Core_DAO::executeQuery($sql, $queryParams);
         while ($dao->fetch()) {
             $filterContactFldIds[$dao->id] = $dao->{$idFldName};
             if (!CRM_Utils_System::isNull($dao->{$idFldName})) {
                 $filterIds[$dao->id] = $dao->{$idFldName};
             }
         }
     }
     if (empty($filterContactFldIds)) {
         $filterContactFldIds[] = 0;
     }
     // retrieve only required contact information
     $extraParams[] = array('contact_type', '=', $contactType, 0, 0);
     // we do token replacement in the replaceGreetingTokens hook
     list($greetingDetails) = CRM_Utils_Token::getTokenDetails(array_keys($filterContactFldIds), $greetingsReturnProperties, FALSE, FALSE, $extraParams);
     // perform token replacement and build update SQL
     $contactIds = array();
     $cacheFieldQuery = "UPDATE civicrm_contact SET {$greeting}_display = CASE id ";
     foreach ($greetingDetails as $contactID => $contactDetails) {
         if (!$processAll && !array_key_exists($contactID, $filterContactFldIds)) {
             continue;
         }
         if ($processOnlyIdSet && !array_key_exists($contactID, $filterIds)) {
             continue;
         }
         if ($id) {
             $greetingString = $originalGreetingString;
             $contactIds[] = $contactID;
         } else {
             if ($greetingBuffer = CRM_Utils_Array::value($filterContactFldIds[$contactID], $allGreetings)) {
                 $greetingString = $greetingBuffer;
             }
         }
         self::processGreetingTemplate($greetingString, $contactDetails, $contactID, 'CRM_UpdateGreeting');
         $greetingString = CRM_Core_DAO::escapeString($greetingString);
         $cacheFieldQuery .= " WHEN {$contactID} THEN '{$greetingString}' ";
         $allContactIds[] = $contactID;
     }
     if (!empty($allContactIds)) {
         $cacheFieldQuery .= " ELSE {$greeting}_display\n                              END;";
         if (!empty($contactIds)) {
             // need to update greeting _id field.
             // reset greeting _custom
             $resetCustomGreeting = '';
             if ($valueID != 4) {
                 $resetCustomGreeting = ", {$greeting}_custom = NULL ";
             }
             $queryString = "\nUPDATE civicrm_contact\nSET {$greeting}_id = {$valueID}\n    {$resetCustomGreeting}\nWHERE id IN (" . implode(',', $contactIds) . ")";
             CRM_Core_DAO::executeQuery($queryString);
         }
         // now update cache field
         CRM_Core_DAO::executeQuery($cacheFieldQuery);
     }
 }
コード例 #20
0
/**
 * 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
 */
function _civicrm_api3_deprecated_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_api3_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_api3_store_values($fields[$values['contact_type']], $values, $params);
        return TRUE;
    }
    if (isset($values['individual_prefix'])) {
        if (!empty($params['prefix_id'])) {
            $prefixes = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id');
            $params['prefix'] = $prefixes[$params['prefix_id']];
        } else {
            $params['prefix'] = $values['individual_prefix'];
        }
        return TRUE;
    }
    if (isset($values['individual_suffix'])) {
        if (!empty($params['suffix_id'])) {
            $suffixes = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id');
            $params['suffix'] = $suffixes[$params['suffix_id']];
        } else {
            $params['suffix'] = $values['individual_suffix'];
        }
        return TRUE;
    }
    // CRM-4575
    if (isset($values['email_greeting'])) {
        if (!empty($params['email_greeting_id'])) {
            $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 (!empty($params['postal_greeting_id'])) {
            $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 (!empty($params['addressee_id'])) {
            $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 (!empty($params['gender_id'])) {
            $genders = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id');
            $params['gender'] = $genders[$params['gender_id']];
        } else {
            $params['gender'] = $values['gender'];
        }
        return TRUE;
    }
    if (!empty($values['preferred_communication_method'])) {
        $comm = array();
        $pcm = array_change_key_case(array_flip(CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method')), 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;
    }
    // format the website params.
    if (!empty($values['url'])) {
        static $websiteFields;
        if (!is_array($websiteFields)) {
            require_once 'CRM/Core/DAO/Website.php';
            $websiteFields = CRM_Core_DAO_Website::fields();
        }
        if (!array_key_exists('website', $params) || !is_array($params['website'])) {
            $params['website'] = array();
        }
        $websiteCount = count($params['website']);
        _civicrm_api3_store_values($websiteFields, $values, $params['website'][++$websiteCount]);
        return TRUE;
    }
    // get the formatted location blocks into params - w/ 3.0 format, CRM-4605
    if (!empty($values['location_type_id'])) {
        _civicrm_api3_deprecated_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_api3_store_values($fields['Note'], $values, $params['note'][$noteBlock]);
        return TRUE;
    }
    // Check for custom field values
    if (empty($fields['custom'])) {
        $fields['custom'] =& CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $values), FALSE, FALSE, NULL, NULL, FALSE, FALSE, FALSE);
    }
    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_api3_create_error('Invalid custom field ID');
            } else {
                $params[$key] = $value;
            }
        }
    }
}
コード例 #21
0
ファイル: Event.php プロジェクト: hampelm/Ginsberg-CiviDemo
 /**  
  * 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];
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #22
0
ファイル: UFGroup.php プロジェクト: bhirsch/voipdev
 /**
  * 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);
         }
     }
 }
コード例 #23
0
 /**
  * Build the form object elements for Communication Preferences object.
  *
  * @param CRM_Core_Form $form
  *   Reference to the form object.
  */
 public static function buildQuickForm(&$form)
 {
     // since the pcm - preferred communication method is logically
     // grouped hence we'll use groups of HTML_QuickForm
     // checkboxes for DO NOT phone, email, mail
     // we take labels from SelectValues
     $privacy = $commPreff = $commPreference = array();
     $privacyOptions = CRM_Core_SelectValues::privacy();
     // we add is_opt_out as a separate checkbox below for display and help purposes so remove it here
     unset($privacyOptions['is_opt_out']);
     foreach ($privacyOptions as $name => $label) {
         $privacy[] = $form->createElement('advcheckbox', $name, NULL, $label);
     }
     $form->addGroup($privacy, 'privacy', ts('Privacy'), '&nbsp;<br/>');
     // preferred communication method
     $comm = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method', array('loclize' => TRUE));
     foreach ($comm as $value => $title) {
         $commPreff[] = $form->createElement('advcheckbox', $value, NULL, $title);
     }
     $form->addField('preferred_communication_method', array('entity' => 'contact', 'type' => 'CheckBoxGroup'));
     $form->addField('preferred_language', array('entity' => 'contact'));
     if (!empty($privacyOptions)) {
         $commPreference['privacy'] = $privacyOptions;
     }
     if (!empty($comm)) {
         $commPreference['preferred_communication_method'] = $comm;
     }
     //using for display purpose.
     $form->assign('commPreference', $commPreference);
     $form->addField('preferred_mail_format', array('entity' => 'contact', 'label' => ts('Email Format')));
     $form->addField('is_opt_out', array('entity' => 'contact', 'label' => ts('NO BULK EMAILS (User Opt Out)')));
     $form->addField('communication_style_id', array('entity' => 'contact', 'type' => 'RadioGroup'));
     //check contact type and build filter clause accordingly for greeting types, CRM-4575
     $greetings = self::getGreetingFields($form->_contactType);
     foreach ($greetings as $greeting => $fields) {
         $filter = array('contact_type' => $form->_contactType, 'greeting_type' => $greeting);
         //add addressee in Contact form
         $greetingTokens = CRM_Core_PseudoConstant::greeting($filter);
         if (!empty($greetingTokens)) {
             $form->addElement('select', $fields['field'], $fields['label'], array('' => ts('- select -')) + $greetingTokens);
             //custom addressee
             $form->addElement('text', $fields['customField'], $fields['customLabel'], CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', $fields['customField']), $fields['js']);
         }
     }
 }
コード例 #24
0
 /**
  * Function to process greetings and cache
  *
  */
 static function processGreetings(&$contact, $useDefaults = FALSE)
 {
     if ($useDefaults) {
         //retrieve default greetings
         $defaultGreetings = CRM_Core_PseudoConstant::greetingDefaults();
         $contactDefaults = $defaultGreetings[$contact->contact_type];
     }
     // store object values to an array
     $contactDetails = array();
     CRM_Core_DAO::storeValues($contact, $contactDetails);
     $contactDetails = array(array($contact->id => $contactDetails));
     $emailGreetingString = $postalGreetingString = $addresseeString = NULL;
     $updateQueryString = array();
     //cache email and postal greeting to greeting display
     if ($contact->email_greeting_custom != 'null' && $contact->email_greeting_custom) {
         $emailGreetingString = $contact->email_greeting_custom;
     } elseif ($contact->email_greeting_id != 'null' && $contact->email_greeting_id) {
         // the filter value for Individual contact type is set to 1
         $filter = array('contact_type' => $contact->contact_type, 'greeting_type' => 'email_greeting');
         $emailGreeting = CRM_Core_PseudoConstant::greeting($filter);
         $emailGreetingString = $emailGreeting[$contact->email_greeting_id];
         $updateQueryString[] = " email_greeting_custom = NULL ";
     } else {
         if ($useDefaults) {
             reset($contactDefaults['email_greeting']);
             $emailGreetingID = key($contactDefaults['email_greeting']);
             $emailGreetingString = $contactDefaults['email_greeting'][$emailGreetingID];
             $updateQueryString[] = " email_greeting_id = {$emailGreetingID} ";
             $updateQueryString[] = " email_greeting_custom = NULL ";
         } elseif ($contact->email_greeting_custom) {
             $updateQueryString[] = " email_greeting_display = NULL ";
         }
     }
     if ($emailGreetingString) {
         CRM_Utils_Token::replaceGreetingTokens($emailGreetingString, $contactDetails, $contact->id, 'CRM_Contact_BAO_Contact');
         $emailGreetingString = CRM_Core_DAO::escapeString(CRM_Utils_String::stripSpaces($emailGreetingString));
         $updateQueryString[] = " email_greeting_display = '{$emailGreetingString}'";
     }
     //postal greetings
     if ($contact->postal_greeting_custom != 'null' && $contact->postal_greeting_custom) {
         $postalGreetingString = $contact->postal_greeting_custom;
     } elseif ($contact->postal_greeting_id != 'null' && $contact->postal_greeting_id) {
         $filter = array('contact_type' => $contact->contact_type, 'greeting_type' => 'postal_greeting');
         $postalGreeting = CRM_Core_PseudoConstant::greeting($filter);
         $postalGreetingString = $postalGreeting[$contact->postal_greeting_id];
         $updateQueryString[] = " postal_greeting_custom = NULL ";
     } else {
         if ($useDefaults) {
             reset($contactDefaults['postal_greeting']);
             $postalGreetingID = key($contactDefaults['postal_greeting']);
             $postalGreetingString = $contactDefaults['postal_greeting'][$postalGreetingID];
             $updateQueryString[] = " postal_greeting_id = {$postalGreetingID} ";
             $updateQueryString[] = " postal_greeting_custom = NULL ";
         } elseif ($contact->postal_greeting_custom) {
             $updateQueryString[] = " postal_greeting_display = NULL ";
         }
     }
     if ($postalGreetingString) {
         CRM_Utils_Token::replaceGreetingTokens($postalGreetingString, $contactDetails, $contact->id, 'CRM_Contact_BAO_Contact');
         $postalGreetingString = CRM_Core_DAO::escapeString(CRM_Utils_String::stripSpaces($postalGreetingString));
         $updateQueryString[] = " postal_greeting_display = '{$postalGreetingString}'";
     }
     // addressee
     if ($contact->addressee_custom != 'null' && $contact->addressee_custom) {
         $addresseeString = $contact->addressee_custom;
     } elseif ($contact->addressee_id != 'null' && $contact->addressee_id) {
         $filter = array('contact_type' => $contact->contact_type, 'greeting_type' => 'addressee');
         $addressee = CRM_Core_PseudoConstant::greeting($filter);
         $addresseeString = $addressee[$contact->addressee_id];
         $updateQueryString[] = " addressee_custom = NULL ";
     } else {
         if ($useDefaults) {
             reset($contactDefaults['addressee']);
             $addresseeID = key($contactDefaults['addressee']);
             $addresseeString = $contactDefaults['addressee'][$addresseeID];
             $updateQueryString[] = " addressee_id = {$addresseeID} ";
             $updateQueryString[] = " addressee_custom = NULL ";
         } elseif ($contact->addressee_custom) {
             $updateQueryString[] = " addressee_display = NULL ";
         }
     }
     if ($addresseeString) {
         CRM_Utils_Token::replaceGreetingTokens($addresseeString, $contactDetails, $contact->id, 'CRM_Contact_BAO_Contact');
         $addresseeString = CRM_Core_DAO::escapeString(CRM_Utils_String::stripSpaces($addresseeString));
         $updateQueryString[] = " addressee_display = '{$addresseeString}'";
     }
     if (!empty($updateQueryString)) {
         $updateQueryString = implode(',', $updateQueryString);
         $queryString = "UPDATE civicrm_contact SET {$updateQueryString} WHERE id = {$contact->id}";
         CRM_Core_DAO::executeQuery($queryString);
     }
 }