public function postProcess() { $config = CRM_Chapters_AutomatchConfig::singelton(); if ($this->_action & CRM_Core_Action::DELETE) { CRM_Core_BAO_CustomValue::deleteCustomValue($this->id, $config->getCustomGroup('id')); $this->updateAllContacts(); return; } $cg = 'custom_'; $id = ':-1'; if ($this->id) { $id = ':' . $this->id; } $data['entity_id'] = $this->contact_id; $data[$cg . $config->getMatchTypeField('id') . $id] = $this->_submitValues['type']; $data[$cg . $config->getCountryField('id') . $id] = $this->_submitValues['country']; $data[$cg . $config->getZipCodeRangeFromField('id') . $id] = $this->_submitValues['zipcode_from']; $data[$cg . $config->getZipCodeRangeToField('id') . $id] = $this->_submitValues['zipcode_to']; civicrm_api3('CustomValue', 'create', $data); $this->updateAllContacts(); }
/** * The post processing of the form gets done here. * * Key things done during post processing are * - check for reset or next request. if present, skip post procesing. * - now check if user requested running a saved search, if so, then * the form values associated with the saved search are used for searching. * - if user has done a submit with new values the regular post submissing is * done. * The processing consists of using a Selector / Controller framework for getting the * search results. * * @param * * @return void * @access public */ function postProcess() { $session =& CRM_Core_Session::singleton(); $session->set('isAdvanced', '1'); // get user submitted values // get it from controller only if form has been submitted, else preProcess has set this if (!empty($_POST)) { $this->_formValues = $this->controller->exportValues($this->_name); // FIXME: couldn't figure out a good place to do this, // FIXME: so leaving this as a dependency for now if (array_key_exists('contribution_amount_low', $this->_formValues)) { foreach (array('contribution_amount_low', 'contribution_amount_high') as $f) { $this->_formValues[$f] = CRM_Utils_Rule::cleanMoney($this->_formValues[$f]); } } //assigning event values for autocomplete event selection $eventSearchIds = array('event_id' => 'event_name_id', 'event_type' => 'event_type_id', 'participant_fee_level' => 'participant_fee_id'); foreach ($eventSearchIds as $key => $value) { $this->_formValues[$key] = empty($this->_formValues[$key]) ? '' : $this->_formValues[$value]; $this->_formValues[$value] = ''; } // set the group if group is submitted if ($this->_formValues['uf_group_id']) { $this->set('id', $this->_formValues['uf_group_id']); } else { $this->set('id', ''); } } // retrieve ssID values only if formValues is null, i.e. form has never been posted if (empty($this->_formValues) && isset($this->_ssID)) { $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID); } if (isset($this->_groupID) && !CRM_Utils_Array::value('group', $this->_formValues)) { $this->_formValues['group'] = array($this->_groupID => 1); } //search for civicase if (is_array($this->_formValues)) { if (array_key_exists('case_owner', $this->_formValues) && !$this->_formValues['case_owner'] && !$this->_force) { $this->_formValues['case_owner'] = 0; } else { if (array_key_exists('case_owner', $this->_formValues)) { $this->_formValues['case_owner'] = 1; } } } // we dont want to store the sortByCharacter in the formValue, it is more like // a filter on the result set // this filter is reset if we click on the search button if ($this->_sortByCharacter && empty($_POST)) { if ($this->_sortByCharacter == 1) { $this->_formValues['sortByCharacter'] = null; } else { $this->_formValues['sortByCharacter'] = $this->_sortByCharacter; } } require_once 'CRM/Core/BAO/CustomValue.php'; CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($this->_formValues); require_once 'CRM/Contact/BAO/Query.php'; $this->_params =& CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $this->_returnProperties =& $this->returnProperties(); parent::postProcess(); }
/** * Delete custom value. */ public static function deleteCustomValue() { CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain'); $customValueID = CRM_Utils_Type::escape($_REQUEST['valueID'], 'Positive'); $customGroupID = CRM_Utils_Type::escape($_REQUEST['groupID'], 'Positive'); $contactId = CRM_Utils_Request::retrieve('contactId', 'Positive', CRM_Core_DAO::$_nullObject); CRM_Core_BAO_CustomValue::deleteCustomValue($customValueID, $customGroupID); if ($contactId) { echo CRM_Contact_BAO_Contact::getCountComponent('custom_' . $customGroupID, $contactId); } CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush(); CRM_Utils_System::civiExit(); }
/** * The post processing of the form gets done here. * * Key things done during post processing are * - check for reset or next request. if present, skip post procesing. * - now check if user requested running a saved search, if so, then * the form values associated with the saved search are used for searching. * - if user has done a submit with new values the regular post submissing is * done. * The processing consists of using a Selector / Controller framework for getting the * search results. * * @param * * @return void * @access public */ function postProcess() { if ($this->_done) { return; } $this->_done = TRUE; $this->_formValues = $this->controller->exportValues($this->_name); $this->fixFormValues(); // We don't show test records in summaries or dashboards if (empty($this->_formValues['member_test']) && $this->_force) { $this->_formValues["member_test"] = 0; } CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($this->_formValues); $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $this->set('formValues', $this->_formValues); $this->set('queryParams', $this->_queryParams); $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->_actionButtonName) { // check actionName and if next, then do not repeat a search, since we are going to the next page // hack, make sure we reset the task values $stateMachine = $this->controller->getStateMachine(); $formName = $stateMachine->getTaskFormName(); $this->controller->resetPage($formName); return; } $sortID = NULL; if ($this->get(CRM_Utils_Sort::SORT_ID)) { $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), $this->get(CRM_Utils_Sort::SORT_DIRECTION)); } $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $selector = new CRM_Member_Selector_Search($this->_queryParams, $this->_action, NULL, $this->_single, $this->_limit, $this->_context); $selector->setKey($this->controller->_key); $prefix = NULL; if ($this->_context == 'basic') { $prefix = $this->_prefix; } $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SESSION, $prefix); $controller->setEmbedded(TRUE); $query =& $selector->getQuery(); $controller->run(); }
function validate() { if (CRM_Utils_System::isNull($this->_value)) { return true; } switch ($this->_name) { case 'contact_id': // note: we validate extistence of the contact in API, upon // insert (it would be too costlty to do a db call here) return CRM_Utils_Rule::integer($this->_value); break; case 'receive_date': case 'cancel_date': case 'receipt_date': case 'thankyou_date': return CRM_Utils_Rule::date($this->_value); break; case 'non_deductible_amount': case 'total_amount': case 'fee_amount': case 'net_amount': return CRM_Utils_Rule::money($this->_value); break; case 'trxn_id': static $seenTrxnIds = array(); if (in_array($this->_value, $seenTrxnIds)) { return false; } elseif ($this->_value) { $seenTrxnIds[] = $this->_value; return true; } else { $this->_value = null; return true; } break; case 'currency': return CRM_Utils_Rule::currencyCode($this->_value); break; case 'contribution_type': static $contributionTypes = null; if (!$contributionTypes) { $contributionTypes =& CRM_Contribute_PseudoConstant::contributionType(); } if (in_array($this->_value, $contributionTypes)) { return true; } else { return false; } break; case 'payment_instrument': static $paymentInstruments = null; if (!$paymentInstruments) { $paymentInstruments =& CRM_Contribute_PseudoConstant::paymentInstrument(); } if (in_array($this->_value, $paymentInstruments)) { return true; } else { return false; } break; default: break; } // check whether that's a valid custom field id // and if so, check the contents' validity if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($this->_name)) { static $customFields = null; if (!$customFields) { $customFields =& CRM_Core_BAO_CustomField::getFields('Contribution'); } if (!array_key_exists($customFieldID, $customFields)) { return false; } return CRM_Core_BAO_CustomValue::typecheck($customFields[$customFieldID]['data_type'], $this->_value); } return true; }
/** * The post processing of the form gets done here. * * Key things done during post processing are * - check for reset or next request. if present, skip post procesing. * - now check if user requested running a saved search, if so, then * the form values associated with the saved search are used for searching. * - if user has done a submit with new values the regular post submissing is * done. * The processing consists of using a Selector / Controller framework for getting the * search results. */ public function postProcess() { if ($this->_done) { return; } $this->_done = TRUE; $this->_formValues = $this->controller->exportValues($this->_name); $this->fixFormValues(); if (isset($this->_ssID) && empty($_POST)) { // if we are editing / running a saved search and the form has not been posted $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID); } //search for civicase if (!$this->_force) { if (array_key_exists('case_owner', $this->_formValues) && !$this->_formValues['case_owner']) { $this->_formValues['case_owner'] = 0; } } if (empty($this->_formValues['case_deleted'])) { $this->_formValues['case_deleted'] = 0; } CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues); $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $this->set('formValues', $this->_formValues); $this->set('queryParams', $this->_queryParams); $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->_actionButtonName) { // check actionName and if next, then do not repeat a search, since we are going to the next page // hack, make sure we reset the task values $stateMachine = $this->controller->getStateMachine(); $formName = $stateMachine->getTaskFormName(); $this->controller->resetPage($formName); return; } $sortID = NULL; if ($this->get(CRM_Utils_Sort::SORT_ID)) { $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), $this->get(CRM_Utils_Sort::SORT_DIRECTION)); } $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $selector = new CRM_Case_Selector_Search($this->_queryParams, $this->_action, NULL, $this->_single, $this->_limit, $this->_context); $selector->setKey($this->controller->_key); $prefix = NULL; if ($this->_context == 'user') { $prefix = $this->_prefix; } $this->assign("{$prefix}limit", $this->_limit); $this->assign("{$prefix}single", $this->_single); $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SESSION, $prefix); $controller->setEmbedded(TRUE); $query =& $selector->getQuery(); if ($this->_context == 'user') { $query->setSkipPermission(TRUE); } $controller->run(); }
/** * The post processing of the form gets done here. * * Key things done during post processing are * - check for reset or next request. if present, skip post procesing. * - now check if user requested running a saved search, if so, then * the form values associated with the saved search are used for searching. * - if user has done a submit with new values the regular post submissing is * done. * The processing consists of using a Selector / Controller framework for getting the * search results. * * @param * * @return void * @access public */ function postProcess() { $this->set('isAdvanced', '1'); // get user submitted values // get it from controller only if form has been submitted, else preProcess has set this if (!empty($_POST)) { $this->_formValues = $this->controller->exportValues($this->_name); $this->normalizeFormValues(); // FIXME: couldn't figure out a good place to do this, // FIXME: so leaving this as a dependency for now if (array_key_exists('contribution_amount_low', $this->_formValues)) { foreach (array('contribution_amount_low', 'contribution_amount_high') as $f) { $this->_formValues[$f] = CRM_Utils_Rule::cleanMoney($this->_formValues[$f]); } } // set the group if group is submitted if (!empty($this->_formValues['uf_group_id'])) { $this->set('id', $this->_formValues['uf_group_id']); } else { $this->set('id', ''); } } // retrieve ssID values only if formValues is null, i.e. form has never been posted if (empty($this->_formValues) && isset($this->_ssID)) { $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID); } if (isset($this->_groupID) && !CRM_Utils_Array::value('group', $this->_formValues)) { $this->_formValues['group'] = array($this->_groupID => 1); } //search for civicase if (is_array($this->_formValues)) { $allCases = FALSE; if (array_key_exists('case_owner', $this->_formValues) && !$this->_formValues['case_owner'] && !$this->_force) { foreach (array('case_type_id', 'case_status_id', 'case_deleted', 'case_tags') as $caseCriteria) { if (CRM_Utils_Array::value($caseCriteria, $this->_formValues)) { $allCases = TRUE; $this->_formValues['case_owner'] = 1; continue; } } if ($allCases) { if (CRM_Core_Permission::check('access all cases and activities')) { $this->_formValues['case_owner'] = 1; } else { $this->_formValues['case_owner'] = 2; } } else { $this->_formValues['case_owner'] = 0; } } } // we dont want to store the sortByCharacter in the formValue, it is more like // a filter on the result set // this filter is reset if we click on the search button if ($this->_sortByCharacter !== NULL && empty($_POST)) { if (strtolower($this->_sortByCharacter) == 'all') { $this->_formValues['sortByCharacter'] = NULL; } else { $this->_formValues['sortByCharacter'] = $this->_sortByCharacter; } } else { $this->_sortByCharacter = NULL; } CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($this->_formValues); $this->_params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $this->_returnProperties =& $this->returnProperties(); parent::postProcess(); }
/** * The post processing of the form gets done here. * * Key things done during post processing are * - check for reset or next request. if present, skip post processing. * - now check if user requested running a saved search, if so, then * the form values associated with the saved search are used for searching. * - if user has done a submit with new values the regular post submission is * done. * The processing consists of using a Selector / Controller framework for getting the * search results. */ public function postProcess() { if ($this->_done) { return; } $this->_done = TRUE; if (!empty($_POST)) { $this->_formValues = $this->controller->exportValues($this->_name); } $this->fixFormValues(); // We don't show test records in summaries or dashboards if (empty($this->_formValues['contribution_test']) && $this->_force && !empty($this->_context) && $this->_context == 'dashboard') { $this->_formValues["contribution_test"] = 0; } foreach (array('contribution_amount_low', 'contribution_amount_high') as $f) { if (isset($this->_formValues[$f])) { $this->_formValues[$f] = CRM_Utils_Rule::cleanMoney($this->_formValues[$f]); } } $config = CRM_Core_Config::singleton(); if (!empty($_POST)) { $specialParams = array('financial_type_id', 'contribution_soft_credit_type_id', 'contribution_status_id', 'contribution_source', 'contribution_trxn_id', 'contribution_page_id', 'contribution_product_id'); foreach ($specialParams as $element) { $value = CRM_Utils_Array::value($element, $this->_formValues); if ($value) { if (is_array($value)) { $this->_formValues[$element] = array('IN' => $value); } else { $this->_formValues[$element] = array('LIKE' => "%{$value}%"); } } } $tags = CRM_Utils_Array::value('contact_tags', $this->_formValues); if ($tags && !is_array($tags)) { unset($this->_formValues['contact_tags']); $this->_formValues['contact_tags'][$tags] = 1; } if ($tags && is_array($tags)) { unset($this->_formValues['contact_tags']); foreach ($tags as $notImportant => $tagID) { $this->_formValues['contact_tags'][$tagID] = 1; } } if (!$config->groupTree) { $group = CRM_Utils_Array::value('group', $this->_formValues); if ($group && !is_array($group)) { unset($this->_formValues['group']); $this->_formValues['group'][$group] = 1; } if ($group && is_array($group)) { unset($this->_formValues['group']); foreach ($group as $notImportant => $groupID) { $this->_formValues['group'][$groupID] = 1; } } } } CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($this->_formValues); $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $this->set('formValues', $this->_formValues); $this->set('queryParams', $this->_queryParams); $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->_actionButtonName) { // check actionName and if next, then do not repeat a search, since we are going to the next page // hack, make sure we reset the task values $stateMachine = $this->controller->getStateMachine(); $formName = $stateMachine->getTaskFormName(); $this->controller->resetPage($formName); return; } $sortID = NULL; if ($this->get(CRM_Utils_Sort::SORT_ID)) { $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), $this->get(CRM_Utils_Sort::SORT_DIRECTION)); } $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $selector = new CRM_Contribute_Selector_Search($this->_queryParams, $this->_action, NULL, $this->_single, $this->_limit, $this->_context); $selector->setKey($this->controller->_key); $prefix = NULL; if ($this->_context == 'basic' || $this->_context == 'user') { $prefix = $this->_prefix; } $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SESSION, $prefix); $controller->setEmbedded(TRUE); $query =& $selector->getQuery(); if ($this->_context == 'user') { $query->setSkipPermission(TRUE); } $summary =& $query->summaryContribution($this->_context); $this->set('summary', $summary); $this->assign('contributionSummary', $summary); $controller->run(); }
/** * Check if an error in custom data. * * @param array $params * @param string $errorMessage * A string containing all the error-fields. * * @param null $csType * @param null $relationships */ public static function isErrorInCustomData($params, &$errorMessage, $csType = NULL, $relationships = NULL) { $session = CRM_Core_Session::singleton(); $dateType = $session->get("dateTypes"); if (!empty($params['contact_sub_type'])) { $csType = CRM_Utils_Array::value('contact_sub_type', $params); } if (empty($params['contact_type'])) { $params['contact_type'] = 'Individual'; } $customFields = CRM_Core_BAO_CustomField::getFields($params['contact_type'], FALSE, FALSE, $csType); $addressCustomFields = CRM_Core_BAO_CustomField::getFields('Address'); $customFields = $customFields + $addressCustomFields; foreach ($params 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, $customFields)) { self::addToErrorMsg(ts('field ID'), $errorMessage); } // validate null values for required custom fields of type boolean if (!empty($customFields[$customFieldID]['is_required']) && (empty($params['custom_' . $customFieldID]) && !is_numeric($params['custom_' . $customFieldID])) && $customFields[$customFieldID]['data_type'] == 'Boolean') { self::addToErrorMsg($customFields[$customFieldID]['label'] . '::' . $customFields[$customFieldID]['groupTitle'], $errorMessage); } //For address custom fields, we do get actual custom field value as an inner array of //values so need to modify if (array_key_exists($customFieldID, $addressCustomFields)) { $value = $value[0][$key]; } /* validate the data against the CF type */ if ($value) { if ($customFields[$customFieldID]['data_type'] == 'Date') { if (array_key_exists($customFieldID, $addressCustomFields) && CRM_Utils_Date::convertToDefaultDate($params[$key][0], $dateType, $key)) { $value = $params[$key][0][$key]; } elseif (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) { $value = $params[$key]; } else { self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage); } } elseif ($customFields[$customFieldID]['data_type'] == 'Boolean') { if (CRM_Utils_String::strtoboolstr($value) === FALSE) { self::addToErrorMsg($customFields[$customFieldID]['label'] . '::' . $customFields[$customFieldID]['groupTitle'], $errorMessage); } } // need not check for label filed import $htmlType = array('CheckBox', 'Multi-Select', 'AdvMulti-Select', 'Select', 'Radio', 'Multi-Select State/Province', 'Multi-Select Country'); if (!in_array($customFields[$customFieldID]['html_type'], $htmlType) || $customFields[$customFieldID]['data_type'] == 'Boolean' || $customFields[$customFieldID]['data_type'] == 'ContactReference') { $valid = CRM_Core_BAO_CustomValue::typecheck($customFields[$customFieldID]['data_type'], $value); if (!$valid) { self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage); } } // check for values for custom fields for checkboxes and multiselect if ($customFields[$customFieldID]['html_type'] == 'CheckBox' || $customFields[$customFieldID]['html_type'] == 'AdvMulti-Select' || $customFields[$customFieldID]['html_type'] == 'Multi-Select') { $value = trim($value); $value = str_replace('|', ',', $value); $mulValues = explode(',', $value); $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE); foreach ($mulValues as $v1) { if (strlen($v1) == 0) { continue; } $flag = FALSE; foreach ($customOption as $v2) { if (strtolower(trim($v2['label'])) == strtolower(trim($v1)) || strtolower(trim($v2['value'])) == strtolower(trim($v1))) { $flag = TRUE; } } if (!$flag) { self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage); } } } elseif ($customFields[$customFieldID]['html_type'] == 'Select' || $customFields[$customFieldID]['html_type'] == 'Radio' && $customFields[$customFieldID]['data_type'] != 'Boolean') { $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE); $flag = FALSE; foreach ($customOption as $v2) { if (strtolower(trim($v2['label'])) == strtolower(trim($value)) || strtolower(trim($v2['value'])) == strtolower(trim($value))) { $flag = TRUE; } } if (!$flag) { self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage); } } elseif ($customFields[$customFieldID]['html_type'] == 'Multi-Select State/Province') { $mulValues = explode(',', $value); foreach ($mulValues as $stateValue) { if ($stateValue) { if (self::in_value(trim($stateValue), CRM_Core_PseudoConstant::stateProvinceAbbreviation()) || self::in_value(trim($stateValue), CRM_Core_PseudoConstant::stateProvince())) { continue; } else { self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage); } } } } elseif ($customFields[$customFieldID]['html_type'] == 'Multi-Select Country') { $mulValues = explode(',', $value); foreach ($mulValues as $countryValue) { if ($countryValue) { 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(); $error = TRUE; foreach (array($countryNames, $countryIsoCodes, $limitCodes) as $values) { if (in_array(trim($countryValue), $values)) { $error = FALSE; break; } } if ($error) { self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage); } } } } } } elseif (is_array($params[$key]) && isset($params[$key]["contact_type"])) { //CRM-5125 //supporting custom data of related contact subtypes $relation = NULL; if ($relationships) { if (array_key_exists($key, $relationships)) { $relation = $key; } elseif (CRM_Utils_Array::key($key, $relationships)) { $relation = CRM_Utils_Array::key($key, $relationships); } } if (!empty($relation)) { list($id, $first, $second) = CRM_Utils_System::explode('_', $relation, 3); $direction = "contact_sub_type_{$second}"; $relationshipType = new CRM_Contact_BAO_RelationshipType(); $relationshipType->id = $id; if ($relationshipType->find(TRUE)) { if (isset($relationshipType->{$direction})) { $params[$key]['contact_sub_type'] = $relationshipType->{$direction}; } } $relationshipType->free(); } self::isErrorInCustomData($params[$key], $errorMessage, $csType, $relationships); } } }
/** * takes an associative array and creates a contribution object * * @param array $params (reference ) an assoc array of name/value pairs * @param array $ids the array that holds all the db ids * * @return object CRM_Contribute_BAO_Contribution object * @access public * @static */ function &create(&$params, &$ids) { require_once 'CRM/Utils/Money.php'; require_once 'CRM/Utils/Date.php'; // FIXME: a cludgy hack to fix the dates to MySQL format $dateFields = array('receive_date', 'cancel_date', 'receipt_date', 'thankyou_date'); foreach ($dateFields as $df) { if (isset($params[$df])) { $params[$df] = CRM_Utils_Date::isoToMysql($params[$df]); } } CRM_Core_DAO::transaction('BEGIN'); $contribution = CRM_Contribute_BAO_Contribution::add($params, $ids); if (is_a($contribution, 'CRM_Core_Error')) { CRM_Core_DAO::transaction('ROLLBACK'); return $contribution; } $params['contribution_id'] = $contribution->id; // add custom field values if (CRM_Utils_Array::value('custom', $params)) { foreach ($params['custom'] as $customValue) { $cvParams = array('entity_table' => 'civicrm_contribution', 'entity_id' => $contribution->id, 'value' => $customValue['value'], 'type' => $customValue['type'], 'custom_field_id' => $customValue['custom_field_id']); if ($customValue['id']) { $cvParams['id'] = $customValue['id']; } CRM_Core_BAO_CustomValue::create($cvParams); } } // let's create an (or update the relevant) Acitivity History record $contributionType = CRM_Contribute_PseudoConstant::contributionType($contribution->contribution_type_id); if (!$contributionType) { $contributionType = ts('Contribution'); } if (!$GLOBALS['_CRM_CONTRIBUTE_BAO_CONTRIBUTION']['insertDate']) { $GLOBALS['_CRM_CONTRIBUTE_BAO_CONTRIBUTION']['insertDate'] = CRM_Utils_Date::customFormat(date('Y-m-d H:i')); } $activitySummary = ts('%1 - %2 (updated on %3)', array(1 => CRM_Utils_Money::format($contribution->total_amount, $contribution->currency), 2 => $contributionType, 3 => $GLOBALS['_CRM_CONTRIBUTE_BAO_CONTRIBUTION']['insertDate'])); $historyParams = array('entity_table' => 'civicrm_contact', 'entity_id' => $contribution->contact_id, 'activity_type' => $contributionType, 'module' => 'CiviContribute', 'callback' => 'CRM_Contribute_Page_Contribution::details', 'activity_id' => $contribution->id, 'activity_summary' => $activitySummary, 'activity_date' => $contribution->receive_date); if (CRM_Utils_Array::value('contribution', $ids)) { // this contribution should have an Activity History record already $getHistoryParams = array('module' => 'CiviContribute', 'activity_id' => $contribution->id); $getHistoryValues =& CRM_Core_BAO_History::getHistory($getHistoryParams, 0, 1, null, 'Activity'); if (!empty($getHistoryValues)) { $tmp = array_keys($getHistoryValues); $ids['activity_history'] = $tmp[0]; } } $historyDAO =& CRM_Core_BAO_History::create($historyParams, $ids, 'Activity'); if (is_a($historyDAO, 'CRM_Core_Error')) { CRM_Core_Error::fatal("Failed creating Activity History for contribution of id {$contribution->id}"); } CRM_Core_DAO::transaction('COMMIT'); return $contribution; }
/** * Replace all the org-level tokens in $str * * @param string $str The string with tokens to be replaced * @param object $org Associative array of org properties * @param boolean $html Replace tokens with HTML or plain text * @return string The processed string * @access public * @static */ public static function &replaceOrgTokens($str, &$org, $html = false) { self::$_tokens['org'] = array_merge(array_keys(CRM_Contact_BAO_Contact::importableFields('Organization')), array('address', 'display_name', 'checksum', 'contact_id')); /* print "org tokens: <pre>"; print_r( $_tokens['org'] ); print "</pre>"; */ $cv = null; foreach (self::$_tokens['org'] as $token) { // print "Getting token value for $token<br/><br/>"; if ($token == '') { continue; } /* If the string doesn't contain this token, skip it. */ if (!self::token_match('org', $token, $str)) { continue; } /* Construct value from $token and $contact */ $value = null; if ($cfID = CRM_Core_BAO_CustomField::getKeyID($token)) { // only generate cv if we need it if ($cv === null) { $cv =& CRM_Core_BAO_CustomValue::getContactValues($org['contact_id']); } foreach ($cv as $cvFieldID => $value) { if ($cvFieldID == $cfID) { $value = CRM_Core_BAO_CustomOption::getOptionLabel($cfID, $value); break; } } } else { if ($token == 'checksum') { require_once 'CRM/Contact/BAO/Contact/Utils.php'; $cs = CRM_Contact_BAO_Contact_Utils::generateChecksum($org['contact_id']); $value = "cs={$cs}"; } else { if ($token == 'address') { /* Build the location values array */ $loc = array(); $loc['display_name'] = CRM_Utils_Array::retrieveValueRecursive($org, 'display_name'); $loc['street_address'] = CRM_Utils_Array::retrieveValueRecursive($org, 'street_address'); $loc['city'] = CRM_Utils_Array::retrieveValueRecursive($org, 'city'); $loc['state_province'] = CRM_Utils_Array::retrieveValueRecursive($org, 'state_province'); $loc['postal_code'] = CRM_Utils_Array::retrieveValueRecursive($org, 'postal_code'); /* Construct the address token */ $value = CRM_Utils_Address::format($loc); if ($html) { $value = str_replace("\n", '<br />', $value); } } else { /* print "\$org: <pre>"; print_r( $org ); print "</pre>"; */ $value = CRM_Utils_Array::retrieveValueRecursive($org, $token); /* print "\$value: <pre>"; print_r( $value ); print "</pre>"; */ } } } self::token_replace('org', $token, $value, $str); } return $str; }
function searchRange(&$id, &$label, $type, &$value) { $qill = array(); $crmType = CRM_Core_BAO_CustomValue::fieldToType($type); if (isset($value['from'])) { $val = CRM_Utils_Type::escape($value['from'], $crmType); if ($type == 'char_data') { $this->_where[] = CRM_CORE_BAO_CUSTOMQUERY_PREFIX . "{$id}.{$type} >= '{$val}'"; } else { $this->_where[] = CRM_CORE_BAO_CUSTOMQUERY_PREFIX . "{$id}.{$type} >= {$val}"; } $qill[] = ts('greater than "%1"', array(1 => $value['from'])); } if (isset($value['to'])) { $val = CRM_Utils_Type::escape($value['to'], $crmType); if ($type == 'char_data') { $this->_where[] = CRM_CORE_BAO_CUSTOMQUERY_PREFIX . "{$id}.{$type} <= '{$val}'"; } else { $this->_where[] = CRM_CORE_BAO_CUSTOMQUERY_PREFIX . "{$id}.{$type} <= {$val}"; } $qill[] = ts('less than "%1"', array(1 => $value['to'])); } if (!empty($qill)) { $this->_qill[] = $label . ' - ' . implode(' ' . ts('and') . ' ', $qill); } }
/** * Validate a formatted contact parameter list. * * @param array $params Structured parameter list (as in crm_format_params) * * @return bool|CRM_Core_Error * @access public */ function _civicrm_validate_formatted_contact(&$params) { /* Look for offending email addresses */ if (array_key_exists('email', $params)) { foreach ($params['email'] as $count => $values) { if (!is_array($values)) { continue; } if ($email = CRM_Utils_Array::value('email', $values)) { //validate each email if (!CRM_Utils_Rule::email($email)) { return civicrm_create_error('No valid email address'); } //check for loc type id. if (!CRM_Utils_Array::value('location_type_id', $values)) { return civicrm_create_error('Location Type Id missing.'); } } } } /* Validate custom data fields */ if (is_array($params['custom'])) { foreach ($params['custom'] as $key => $custom) { if (is_array($custom)) { $valid = CRM_Core_BAO_CustomValue::typecheck($custom['type'], $custom['value']); if (!$valid) { return civicrm_create_error('Invalid value for custom field \'' . $custom['name'] . '\''); } if ($custom['type'] == 'Date') { $params['custom'][$key]['value'] = str_replace('-', '', $params['custom'][$key]['value']); } } } } return civicrm_create_success(true); }
/** * Validate a formatted contribution parameter list. * * @param array $params Structured parameter list (as in crm_format_params) * * @return bool|CRM_Core_Error * @access public */ function _crm_validate_formatted_contribution(&$params) { static $domainID = null; if (!$domainID) { $config =& CRM_Core_Config::singleton(); $domainID = $config->domainID(); } foreach ($params as $key => $value) { switch ($key) { case 'contact_id': if (!CRM_Utils_Rule::integer($value)) { return _crm_error("contact_id not valid: {$value}"); } $dao =& new CRM_Core_DAO(); $svq = $dao->singleValueQuery("SELECT id FROM civicrm_contact WHERE domain_id = {$domainID} AND id = {$value}"); if (!$svq) { return _crm_error("there's no contact with contact_id of {$value}"); } break; case 'receive_date': case 'cancel_date': case 'receipt_date': case 'thankyou_date': if (!CRM_Utils_Rule::date($value)) { return _crm_error("{$key} not a valid date: {$value}"); } break; case 'non_deductible_amount': case 'total_amount': case 'fee_amount': case 'net_amount': if (!CRM_Utils_Rule::money($value)) { return _crm_error("{$key} not a valid amount: {$value}"); } break; case 'currency': if (!CRM_Utils_Rule::currencyCode($value)) { return _crm_error("currency not a valid code: {$value}"); } break; default: break; } } /* Validate custom data fields */ if (is_array($params['custom'])) { foreach ($params['custom'] as $key => $custom) { if (is_array($custom)) { $valid = CRM_Core_BAO_CustomValue::typecheck($custom['type'], $custom['value']); if (!$valid) { return _crm_error('Invalid value for custom field \'' . $custom['name'] . '\''); } if ($custom['type'] == 'Date') { $params['custom'][$key]['value'] = str_replace('-', '', $params['custom'][$key]['value']); } } } } return true; }
/** * The post processing of the form gets done here. * * Key things done during post processing are * - check for reset or next request. if present, skip post procesing. * - now check if user requested running a saved search, if so, then * the form values associated with the saved search are used for searching. * - if user has done a submit with new values the regular post submissing is * done. * The processing consists of using a Selector / Controller framework for getting the * search results. * * @param * * @return void * @access public */ function postProcess() { if ($this->_done) { return; } $this->_done = true; $this->_formValues = $this->controller->exportValues($this->_name); $this->fixFormValues(); // we don't show test memberships in Contact Summary / User Dashboard // in Search mode by default we hide test memberships if (!CRM_Utils_Array::value('member_test', $this->_formValues)) { $this->_formValues["member_test"] = 0; } require_once 'CRM/Core/BAO/CustomValue.php'; CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($this->_formValues); require_once 'CRM/Contact/BAO/Query.php'; $this->_queryParams =& CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $this->set('formValues', $this->_formValues); $this->set('queryParams', $this->_queryParams); $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->_actionButtonName || $buttonName == $this->_printButtonName) { // check actionName and if next, then do not repeat a search, since we are going to the next page // hack, make sure we reset the task values $stateMachine =& $this->controller->getStateMachine(); $formName = $stateMachine->getTaskFormName(); $this->controller->resetPage($formName); return; } $sortID = null; if ($this->get(CRM_Utils_Sort::SORT_ID)) { $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), $this->get(CRM_Utils_Sort::SORT_DIRECTION)); } require_once 'CRM/Contact/BAO/Query.php'; $this->_queryParams =& CRM_Contact_BAO_Query::convertFormValues($this->_formValues); require_once "CRM/Member/Selector/Search.php"; $selector = new CRM_Member_Selector_Search($this->_queryParams, $this->_action, null, $this->_single, $this->_limit, $this->_context); $selector->setKey($this->controller->_key); $prefix = null; if ($this->_context == 'basic') { $prefix = $this->_prefix; } $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SESSION, $prefix); $controller->setEmbedded(true); $query =& $selector->getQuery(); $controller->run(); }
/** * The post processing of the form gets done here. * * Key things done during post processing are * - check for reset or next request. if present, skip post procesing. * - now check if user requested running a saved search, if so, then * the form values associated with the saved search are used for searching. * - if user has done a submit with new values the regular post submissing is * done. * The processing consists of using a Selector / Controller framework for getting the * search results. * * @param * * @return void */ public function postProcess() { if ($this->_done) { return; } $this->_done = TRUE; if (!empty($_POST)) { $this->_formValues = $this->controller->exportValues($this->_name); CRM_Contact_BAO_Query::processSpecialFormValue($this->_formValues, array('participant_status_id')); } if (empty($this->_formValues)) { $this->_formValues = $this->controller->exportValues($this->_name); } $this->fixFormValues(); if (isset($this->_ssID) && empty($_POST)) { // if we are editing / running a saved search and the form has not been posted $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID); } // We don't show test records in summaries or dashboards if (empty($this->_formValues['participant_test']) && $this->_force) { $this->_formValues["participant_test"] = 0; } CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues); $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, array('event_id')); $this->set('formValues', $this->_formValues); $this->set('queryParams', $this->_queryParams); $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->_actionButtonName) { // check actionName and if next, then do not repeat a search, since we are going to the next page // hack, make sure we reset the task values $stateMachine = $this->controller->getStateMachine(); $formName = $stateMachine->getTaskFormName(); $this->controller->resetPage($formName); return; } $sortID = NULL; if ($this->get(CRM_Utils_Sort::SORT_ID)) { $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), $this->get(CRM_Utils_Sort::SORT_DIRECTION)); } $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, array('event_id')); $selector = new CRM_Event_Selector_Search($this->_queryParams, $this->_action, NULL, $this->_single, $this->_limit, $this->_context); $selector->setKey($this->controller->_key); $prefix = NULL; if ($this->_context == 'user') { $prefix = $this->_prefix; } $this->assign("{$prefix}limit", $this->_limit); $this->assign("{$prefix}single", $this->_single); $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SESSION, $prefix); $controller->setEmbedded(TRUE); $query = $selector->getQuery(); if ($this->_context == 'user') { $query->setSkipPermission(TRUE); } $controller->run(); }
/** * Extract the get params from the url, validate and store it in session. * * @param CRM_Core_Form $form * The form object. * @param string $type * The type of custom group we are using. * * @return array */ public static function extractGetParams(&$form, $type) { if (empty($_GET)) { return array(); } $groupTree = CRM_Core_BAO_CustomGroup::getTree($type); $customValue = array(); $htmlType = array('CheckBox', 'Multi-Select', 'AdvMulti-Select', 'Select', 'Radio'); foreach ($groupTree as $group) { if (!isset($group['fields'])) { continue; } foreach ($group['fields'] as $key => $field) { $fieldName = 'custom_' . $key; $value = CRM_Utils_Request::retrieve($fieldName, 'String', $form, FALSE, NULL, 'GET'); if ($value) { $valid = FALSE; if (!in_array($field['html_type'], $htmlType) || $field['data_type'] == 'Boolean') { $valid = CRM_Core_BAO_CustomValue::typecheck($field['data_type'], $value); } if ($field['html_type'] == 'CheckBox' || $field['html_type'] == 'AdvMulti-Select' || $field['html_type'] == 'Multi-Select') { $value = str_replace("|", ",", $value); $mulValues = explode(',', $value); $customOption = CRM_Core_BAO_CustomOption::getCustomOption($key, TRUE); $val = array(); foreach ($mulValues as $v1) { foreach ($customOption as $coID => $coValue) { if (strtolower(trim($coValue['label'])) == strtolower(trim($v1))) { $val[$coValue['value']] = 1; } } } if (!empty($val)) { $value = $val; $valid = TRUE; } else { $value = NULL; } } elseif ($field['html_type'] == 'Select' || $field['html_type'] == 'Radio' && $field['data_type'] != 'Boolean') { $customOption = CRM_Core_BAO_CustomOption::getCustomOption($key, TRUE); foreach ($customOption as $customID => $coValue) { if (strtolower(trim($coValue['label'])) == strtolower(trim($value))) { $value = $coValue['value']; $valid = TRUE; } } } elseif ($field['data_type'] == 'Date') { if (!empty($value)) { $time = NULL; if (!empty($field['time_format'])) { $time = CRM_Utils_Request::retrieve($fieldName . '_time', 'String', $form, FALSE, NULL, 'GET'); } list($value, $time) = CRM_Utils_Date::setDateDefaults($value . ' ' . $time); if (!empty($field['time_format'])) { $customValue[$fieldName . '_time'] = $time; } } $valid = TRUE; } if ($valid) { $customValue[$fieldName] = $value; } } } } return $customValue; }
/** * The post processing of the form gets done here. * * Key things done during post processing are * - check for reset or next request. if present, skip post procesing. * - now check if user requested running a saved search, if so, then * the form values associated with the saved search are used for searching. * - if user has done a submit with new values the regular post submissing is * done. * The processing consists of using a Selector / Controller framework for getting the * search results. * * @param * * @return void * @access public */ function postProcess() { if ($this->_done) { return; } $this->_done = true; if (!empty($_POST)) { $this->_formValues = $this->controller->exportValues($this->_name); } if (empty($this->_formValues)) { $this->_formValues = $this->controller->exportValues($this->_name); } $this->fixFormValues(); if (isset($this->_ssID) && empty($_POST)) { // if we are editing / running a saved search and the form has not been posted $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID); } // we don't show test registrations in Contact Summary / User Dashboard // in Search mode by default we hide test registrations if (!CRM_Utils_Array::value('participant_test', $this->_formValues)) { $this->_formValues["participant_test"] = 0; } require_once 'CRM/Core/BAO/CustomValue.php'; CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($this->_formValues); require_once 'CRM/Contact/BAO/Query.php'; $this->_queryParams =& CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $this->set('formValues', $this->_formValues); $this->set('queryParams', $this->_queryParams); $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->_actionButtonName || $buttonName == $this->_printButtonName) { // check actionName and if next, then do not repeat a search, since we are going to the next page // hack, make sure we reset the task values $stateMachine =& $this->controller->getStateMachine(); $formName = $stateMachine->getTaskFormName(); $this->controller->resetPage($formName); return; } $sortID = null; if ($this->get(CRM_Utils_Sort::SORT_ID)) { $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), $this->get(CRM_Utils_Sort::SORT_DIRECTION)); } require_once 'CRM/Contact/BAO/Query.php'; $this->_queryParams =& CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $selector =& new CRM_Event_Selector_Search($this->_queryParams, $this->_action, null, $this->_single, $this->_limit, $this->_context); $prefix = null; if ($this->_context == 'user') { $prefix = $this->_prefix; } $this->assign("{$prefix}limit", $this->_limit); $this->assign("{$prefix}single", $this->_single); $controller =& new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SESSION, $prefix); $controller->setEmbedded(true); $query =& $selector->getQuery(); if ($this->_context == 'user') { $query->setSkipPermission(true); } $controller->run(); }
/** * The post processing of the form gets done here. * * Key things done during post processing are * - check for reset or next request. if present, skip post procesing. * - now check if user requested running a saved search, if so, then * the form values associated with the saved search are used for searching. * - if user has done a submit with new values the regular post submissing is * done. * * The processing consists of using a Selector / Controller framework for getting the * search results. */ public function postProcess() { if ($this->_done) { return; } $this->_done = TRUE; if (!empty($_POST)) { $this->_formValues = $this->controller->exportValues($this->_name); foreach (array('activity_type_id', 'status_id', 'activity_subject') as $element) { $value = CRM_Utils_Array::value($element, $this->_formValues); if ($value) { if (is_array($value)) { if ($element == 'status_id') { unset($this->_formValues[$element]); $this->_formValues['activity_' . $element] = $value; } } else { $this->_formValues[$element] = array('LIKE' => "%{$value}%"); } } } } $this->fixFormValues(); if (isset($this->_ssID) && empty($_POST)) { // if we are editing / running a saved search and the form has not been posted $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID); } // We don't show test records in summaries or dashboards if (empty($this->_formValues['activity_test']) && $this->_force) { $this->_formValues["activity_test"] = 0; } CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues); $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $this->set('formValues', $this->_formValues); $this->set('queryParams', $this->_queryParams); $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->_actionButtonName) { // check actionName and if next, then do not repeat a search, since we are going to the next page // hack, make sure we reset the task values $stateMachine = $this->controller->getStateMachine(); $formName = $stateMachine->getTaskFormName(); $this->controller->resetPage($formName); return; } $sortID = NULL; if ($this->get(CRM_Utils_Sort::SORT_ID)) { $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), $this->get(CRM_Utils_Sort::SORT_DIRECTION)); } $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $selector = new CRM_Activity_Selector_Search($this->_queryParams, $this->_action, NULL, $this->_single, $this->_limit, $this->_context); $selector->setKey($this->controller->_key); $prefix = NULL; if ($this->_context == 'basic' || $this->_context == 'user') { $prefix = $this->_prefix; } $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SESSION, $prefix); $controller->setEmbedded(TRUE); $query =& $selector->getQuery(); if ($this->_context == 'user') { $query->setSkipPermission(TRUE); } $controller->run(); }
/** * The post processing of the form gets done here. * * Key things done during post processing are * - check for reset or next request. if present, skip post procesing. * - now check if user requested running a saved search, if so, then * the form values associated with the saved search are used for searching. * - if user has done a submit with new values the regular post submissing is * done. * The processing consists of using a Selector / Controller framework for getting the * search results. * * @param * * @return void * @access public */ function postProcess() { if ($this->_done) { return; } $this->_done = true; if (!empty($_POST)) { $this->_formValues = $this->controller->exportValues($this->_name); } $this->fixFormValues(); // we don't show test contributions in Contact Summary / User Dashboard // in Search mode by default we hide test contributions if (!CRM_Utils_Array::value('contribution_test', $this->_formValues)) { $this->_formValues["contribution_test"] = 0; } foreach (array('contribution_amount_low', 'contribution_amount_high') as $f) { if (isset($this->_formValues[$f])) { $this->_formValues[$f] = CRM_Utils_Rule::cleanMoney($this->_formValues[$f]); } } require_once 'CRM/Core/BAO/CustomValue.php'; CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($this->_formValues); require_once 'CRM/Contact/BAO/Query.php'; $this->_queryParams =& CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $this->set('formValues', $this->_formValues); $this->set('queryParams', $this->_queryParams); $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->_actionButtonName || $buttonName == $this->_printButtonName) { // check actionName and if next, then do not repeat a search, since we are going to the next page // hack, make sure we reset the task values $stateMachine =& $this->controller->getStateMachine(); $formName = $stateMachine->getTaskFormName(); $this->controller->resetPage($formName); return; } $sortID = null; if ($this->get(CRM_Utils_Sort::SORT_ID)) { $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), $this->get(CRM_Utils_Sort::SORT_DIRECTION)); } require_once 'CRM/Contact/BAO/Query.php'; $this->_queryParams =& CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $selector =& new CRM_Contribute_Selector_Search($this->_queryParams, $this->_action, null, $this->_single, $this->_limit, $this->_context); $prefix = null; if ($this->_context == 'basic' || $this->_context == 'user') { $prefix = $this->_prefix; } $controller =& new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SESSION, $prefix); $controller->setEmbedded(true); $query =& $selector->getQuery(); if ($this->_context == 'user') { $query->setSkipPermission(true); } $summary =& $query->summaryContribution(); $this->set('summary', $summary); $this->assign('contributionSummary', $summary); $controller->run(); }
/** * Function to delete custom value * */ function deleteCustomValue(&$config) { $customValueID = CRM_Utils_Type::escape($_POST['valueID'], 'Positive'); $customGroupID = CRM_Utils_Type::escape($_POST['groupID'], 'Positive'); require_once "CRM/Core/BAO/CustomValue.php"; CRM_Core_BAO_CustomValue::deleteCustomValue($customValueID, $customGroupID); if ($contactId = CRM_Utils_Array::value('contactId', $_POST)) { require_once 'CRM/Contact/BAO/Contact.php'; echo CRM_Contact_BAO_Contact::getCountComponent('custom_' . $_POST['groupID'], $contactId); } // reset the group contact cache for this group require_once 'CRM/Contact/BAO/GroupContactCache.php'; CRM_Contact_BAO_GroupContactCache::remove(); }
function _crm_format_custom_params(&$params, &$values, $extends) { $values['custom'] = array(); $customFields = CRM_Core_BAO_CustomField::getFields($extends); foreach ($params 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, $customFields)) { return _crm_error('Invalid custom field ID'); } $fieldType = null; // modified for CRM-1586 // check data type for importing custom field (labels) with data type Integer/Float/Money /* validate the data against the CF type */ if ($customFields[$customFieldID]['data_type'] == "Int" || $customFields[$customFieldID]['data_type'] == "Float" || $customFields[$customFieldID]['data_type'] == "Money") { if ($customFields[$customFieldID]['html_type'] == "Text") { $fieldType = $customFields[$customFieldID]['data_type']; } else { $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID); foreach ($customOption as $customValue => $customLabel) { //check wether $value is label or value if (strtolower($customValue) == strtolower(trim($value))) { $fieldType = "String"; } else { if (strtolower($customValue) == strtolower(trim($value))) { $fieldType = $customFields[$customFieldID]['data_type']; } } } } } else { //set the Field type $fieldType = $customFields[$customFieldID]['data_type']; } $valid = null; //Validate the datatype of $value $valid = CRM_Core_BAO_CustomValue::typecheck($fieldType, $value); //return error, if not valid custom field if (!$valid) { return _crm_error('Invalid value for custom field ' . $customFields[$customFieldID][1]); } // fix the date field if so if ($customFields[$customFieldID]['data_type'] == 'Date') { $value = str_replace('-', '', $value); } // fixed for checkbox and multiselect $newMulValues = array(); if ($customFields[$customFieldID]['html_type'] == 'CheckBox' || $customFields[$customFieldID]['html_type'] == 'Multi-Select') { $value = str_replace(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, ',', trim($value, CRM_Core_BAO_CustomOption::VALUE_SEPERATOR)); $value = str_replace("|", ",", $value); $mulValues = explode(',', $value); $custumOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true); foreach ($mulValues as $v1) { foreach ($customOption as $customValue => $customLabel) { if (strtolower($customLabel) == strtolower(trim($v1)) || strtolower($customValue) == strtolower(trim($v1))) { $newMulValues[] = $customValue; } } } $value = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $newMulValues) . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR; } else { if ($customFields[$customFieldID]['html_type'] == 'Select' || $customFields[$customFieldID]['html_type'] == 'Radio') { $custumOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true); foreach ($customOption as $customValue => $customLabel) { if (strtolower($customLabel) == strtolower(trim($value)) || strtolower($customValue) == strtolower(trim($value))) { $value = $customValue; break; } } } } $values['custom'][$customFieldID] = array('value' => $value, 'extends' => $customFields[$customFieldID]['extends'], 'type' => $customFields[$customFieldID]['data_type'], 'custom_field_id' => $customFieldID); } } }
public function testFixFieldValueOfTypeMemoWithEmptyParams() { $params = array(); $result = CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($params); $this->assertEquals($result, NULL, 'Checking the returned value of type Memo.'); }
/** * Defines 'custom value' within a field for a specific entity table/id combination. * * @param $entity_table String Name of the table that this value is attached to * * @param $entity_id int ID of the object in the relevant table * * @param $custom_field object field type of the value * * @param $data Array data appropriate value for the above custom field * * @param $separator String separator for values for ckeckbox. * * @return newly created custom_value object * * @access public * * */ function crm_create_custom_value($entity_table, $entity_id, &$custom_field, &$data, $separator = null) { _crm_initialize(); if (!isset($entity_table)) { return _crm_error("parameter entity_table is not set "); } if (!isset($entity_id)) { return _crm_error("parameter entity_id is not set "); } if (!isset($custom_field->id) && !isset($custom_field->type)) { return _crm_error("field id ot type is not set in custom_field object"); } if ($separator) { $values = explode($separator, $data['value']); require_once 'CRM/Core/BAO/CustomOption.php'; $data['value'] = implode(CRM_CORE_BAO_CUSTOMOPTION_VALUE_SEPERATOR, $values); } $data['type'] = $custom_field->data_type; $data['custom_field_id'] = $custom_field->id; $data['entity_table'] = $entity_table; $data['entity_id'] = $entity_id; require_once 'CRM/Core/BAO/CustomValue.php'; return CRM_Core_BAO_CustomValue::create($data); }
/** * function to check if an error in custom data * * @param String $errorMessage A string containing all the error-fields. * * @access public */ function isErrorInCustomData($params, &$errorMessage) { $session =& CRM_Core_Session::singleton(); $dateType = $session->get("dateTypes"); //CRM-5125 //add custom fields for contact sub type if (!empty($this->_contactSubType)) { $csType = $this->_contactSubType; } if (CRM_Utils_Array::value('contact_sub_type', $params)) { $csType = CRM_Utils_Array::value('contact_sub_type', $params); } $customFields = CRM_Core_BAO_CustomField::getFields($params['contact_type'], false, false, $csType); foreach ($params 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, $customFields)) { self::addToErrorMsg(ts('field ID'), $errorMessage); } /* validate the data against the CF type */ if ($value) { if ($customFields[$customFieldID]['data_type'] == 'Date') { if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) { $value = $params[$key]; } else { self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage); } } else { if ($customFields[$customFieldID]['data_type'] == 'Boolean') { if (CRM_Utils_String::strtoboolstr($value) === false) { self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage); } } } // need not check for label filed import $htmlType = array('CheckBox', 'Multi-Select', 'AdvMulti-Select', 'Select', 'Radio', 'Multi-Select State/Province', 'Multi-Select Country'); if (!in_array($customFields[$customFieldID]['html_type'], $htmlType) || $customFields[$customFieldID]['data_type'] == 'Boolean') { $valid = CRM_Core_BAO_CustomValue::typecheck($customFields[$customFieldID]['data_type'], $value); if (!$valid) { self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage); } } // check for values for custom fields for checkboxes and multiselect if ($customFields[$customFieldID]['html_type'] == 'CheckBox' || $customFields[$customFieldID]['html_type'] == 'AdvMulti-Select' || $customFields[$customFieldID]['html_type'] == 'Multi-Select') { $value = trim($value); $value = str_replace('|', ',', $value); $mulValues = explode(',', $value); $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true); foreach ($mulValues as $v1) { if (strlen($v1) == 0) { continue; } $flag = false; foreach ($customOption as $v2) { if (strtolower(trim($v2['label'])) == strtolower(trim($v1)) || strtolower(trim($v2['value'])) == strtolower(trim($v1))) { $flag = true; } } if (!$flag) { self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage); } } } else { if ($customFields[$customFieldID]['html_type'] == 'Select' || $customFields[$customFieldID]['html_type'] == 'Radio' && $customFields[$customFieldID]['data_type'] != 'Boolean') { $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true); $flag = false; foreach ($customOption as $v2) { if (strtolower(trim($v2['label'])) == strtolower(trim($value)) || strtolower(trim($v2['value'])) == strtolower(trim($value))) { $flag = true; } } if (!$flag) { self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage); } } else { if ($customFields[$customFieldID]['html_type'] == 'Multi-Select State/Province') { $mulValues = explode(',', $value); foreach ($mulValues as $stateValue) { if ($stateValue) { if (self::in_value(trim($stateValue), CRM_Core_PseudoConstant::stateProvinceAbbreviation()) || self::in_value(trim($stateValue), CRM_Core_PseudoConstant::stateProvince())) { continue; } else { self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage); } } } } else { if ($customFields[$customFieldID]['html_type'] == 'Multi-Select Country') { $mulValues = explode(',', $value); foreach ($mulValues as $countryValue) { if ($countryValue) { 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(); $error = true; foreach (array($countryNames, $countryIsoCodes, $limitCodes) as $values) { if (in_array(trim($countryValue), $values)) { $error = false; break; } } if ($error) { self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage); } } } } } } } } } else { if (is_array($params[$key]) && isset($params[$key]["contact_type"])) { //CRM-5125 //supporting custom data of related contact subtypes if (array_key_exists($key, $this->_relationships)) { $relation = $key; } else { if (CRM_Utils_Array::key($key, $this->_relationships)) { $relation = CRM_Utils_Array::key($key, $this->_relationships); } } if (!empty($relation)) { list($id, $first, $second) = CRM_Utils_System::explode('_', $relation, 3); $direction = "contact_sub_type_{$second}"; require_once 'CRM/Contact/BAO/RelationshipType.php'; $relationshipType =& new CRM_Contact_BAO_RelationshipType(); $relationshipType->id = $id; if ($relationshipType->find(true)) { if (isset($relationshipType->{$direction})) { $params[$key]['contact_sub_type'] = $relationshipType->{$direction}; } } $relationshipType->free(); } self::isErrorInCustomData($params[$key], $errorMessage); } } } }
/** * Function to delete custom value * */ static function deleteCustomValue() { $customValueID = CRM_Utils_Type::escape($_POST['valueID'], 'Positive'); $customGroupID = CRM_Utils_Type::escape($_POST['groupID'], 'Positive'); CRM_Core_BAO_CustomValue::deleteCustomValue($customValueID, $customGroupID); if ($contactId = CRM_Utils_Array::value('contactId', $_POST)) { echo CRM_Contact_BAO_Contact::getCountComponent('custom_' . $_POST['groupID'], $contactId); } // reset the group contact cache for this group CRM_Contact_BAO_GroupContactCache::remove(); CRM_Utils_System::civiExit(); }
/** * Replace all the org-level tokens in $str * * @param string $str * The string with tokens to be replaced. * @param object $org * Associative array of org properties. * @param bool $html * Replace tokens with HTML or plain text. * * @param bool $escapeSmarty * * @return string * The processed string */ public static function &replaceOrgTokens($str, &$org, $html = FALSE, $escapeSmarty = FALSE) { self::$_tokens['org'] = array_merge(array_keys(CRM_Contact_BAO_Contact::importableFields('Organization')), array('address', 'display_name', 'checksum', 'contact_id')); $cv = NULL; foreach (self::$_tokens['org'] as $token) { // print "Getting token value for $token<br/><br/>"; if ($token == '') { continue; } // If the string doesn't contain this token, skip it. if (!self::token_match('org', $token, $str)) { continue; } // Construct value from $token and $contact $value = NULL; if ($cfID = CRM_Core_BAO_CustomField::getKeyID($token)) { // only generate cv if we need it if ($cv === NULL) { $cv = CRM_Core_BAO_CustomValue::getContactValues($org['contact_id']); } foreach ($cv as $cvFieldID => $value) { if ($cvFieldID == $cfID) { $value = CRM_Core_BAO_CustomOption::getOptionLabel($cfID, $value); break; } } } elseif ($token == 'checksum') { $cs = CRM_Contact_BAO_Contact_Utils::generateChecksum($org['contact_id']); $value = "cs={$cs}"; } elseif ($token == 'address') { // Build the location values array $loc = array(); $loc['display_name'] = CRM_Utils_Array::retrieveValueRecursive($org, 'display_name'); $loc['street_address'] = CRM_Utils_Array::retrieveValueRecursive($org, 'street_address'); $loc['city'] = CRM_Utils_Array::retrieveValueRecursive($org, 'city'); $loc['state_province'] = CRM_Utils_Array::retrieveValueRecursive($org, 'state_province'); $loc['postal_code'] = CRM_Utils_Array::retrieveValueRecursive($org, 'postal_code'); // Construct the address token $value = CRM_Utils_Address::format($loc); if ($html) { $value = str_replace("\n", '<br />', $value); } } else { $value = CRM_Utils_Array::retrieveValueRecursive($org, $token); } self::token_replace('org', $token, $value, $str, $escapeSmarty); } return $str; }
/** * Validate a formatted contact parameter list. * * @param array $params * Structured parameter list (as in crm_format_params). * * @return bool|CRM_Core_Error */ function _civicrm_api3_deprecated_validate_formatted_contact(&$params) { // Look for offending email addresses if (array_key_exists('email', $params)) { foreach ($params['email'] as $count => $values) { if (!is_array($values)) { continue; } if ($email = CRM_Utils_Array::value('email', $values)) { // validate each email if (!CRM_Utils_Rule::email($email)) { return civicrm_api3_create_error('No valid email address'); } // check for loc type id. if (empty($values['location_type_id'])) { return civicrm_api3_create_error('Location Type Id missing.'); } } } } // Validate custom data fields if (array_key_exists('custom', $params) && is_array($params['custom'])) { foreach ($params['custom'] as $key => $custom) { if (is_array($custom)) { foreach ($custom as $fieldId => $value) { $valid = CRM_Core_BAO_CustomValue::typecheck(CRM_Utils_Array::value('type', $value), CRM_Utils_Array::value('value', $value)); if (!$valid && $value['is_required']) { return civicrm_api3_create_error('Invalid value for custom field \'' . CRM_Utils_Array::value('name', $custom) . '\''); } if (CRM_Utils_Array::value('type', $custom) == 'Date') { $params['custom'][$key][$fieldId]['value'] = str_replace('-', '', $params['custom'][$key][$fieldId]['value']); } } } } } return civicrm_api3_create_success(TRUE); }
/** * @return bool */ public function validate() { if (CRM_Utils_System::isNull($this->_value)) { return TRUE; } switch ($this->_name) { case 'contact_id': // note: we validate extistence of the contact in API, upon // insert (it would be too costlty to do a db call here) return CRM_Utils_Rule::integer($this->_value); case 'register_date': return CRM_Utils_Rule::date($this->_value); /* @codingStandardsIgnoreStart case 'event_id': static $events = null; if (!$events) { $events = CRM_Event_PseudoConstant::event(); } if (in_array($this->_value, $events)) { return true; } else { return false; } break; @codingStandardsIgnoreEnd */ /* @codingStandardsIgnoreStart case 'event_id': static $events = null; if (!$events) { $events = CRM_Event_PseudoConstant::event(); } if (in_array($this->_value, $events)) { return true; } else { return false; } break; @codingStandardsIgnoreEnd */ default: break; } // check whether that's a valid custom field id // and if so, check the contents' validity if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($this->_name)) { static $customFields = NULL; if (!$customFields) { $customFields = CRM_Core_BAO_CustomField::getFields('Participant'); } if (!array_key_exists($customFieldID, $customFields)) { return FALSE; } return CRM_Core_BAO_CustomValue::typecheck($customFields[$customFieldID]['data_type'], $this->_value); } return TRUE; }
/** * Function to extract the get params from the url, validate * and store it in session * * @param CRM_Core_Form $form the form object * @param string $type the type of custom group we are using * @return void * @access public * @static */ function extractGetParams(&$form, $type) { // if not GET params return if (empty($_GET)) { return; } $groupTree =& CRM_Core_BAO_CustomGroup::getTree($type); $customFields =& CRM_Core_BAO_CustomField::getFields($type); $customValue = array(); $htmlType = array('CheckBox', 'Multi-Select', 'Select', 'Radio'); foreach ($groupTree as $group) { foreach ($group['fields'] as $key => $field) { $fieldName = 'custom_' . $key; $value = CRM_Utils_Request::retrieve($fieldName, $form); if ($value) { if (!in_array($customFields[$key][3], $htmlType) || $customFields[$key][2] == 'Boolean') { $valid = CRM_Core_BAO_CustomValue::typecheck($customFields[$key][2], $value); } if ($customFields[$key][3] == 'CheckBox' || $customFields[$key][3] == 'Multi-Select') { $value = str_replace("|", ",", $value); $mulValues = explode(',', $value); $customOption = CRM_Core_BAO_CustomOption::getCustomOption($key, true); $val = array(); foreach ($mulValues as $v1) { foreach ($customOption as $v2) { if (strtolower(trim($v2['label'])) == strtolower(trim($v1))) { $val[$v2['value']] = 1; } } } if (!empty($val)) { $value = $val; $valid = true; } else { $value = null; } } else { if ($customFields[$key][3] == 'Select' || $customFields[$key][3] == 'Radio' && $customFields[$key][2] != 'Boolean') { $customOption = CRM_Core_BAO_CustomOption::getCustomOption($key, true); foreach ($customOption as $v2) { if (strtolower(trim($v2['label'])) == strtolower(trim($value))) { $value = $v2['value']; $valid = true; } } } else { if ($customFields[$key][2] == 'Date') { require_once 'CRM/Utils/Date.php'; if (is_numeric($value)) { $value = CRM_Utils_Date::unformat($value, null); } else { $value = CRM_Utils_Date::unformat($value, $separator = '-'); } $valid = true; } } } if ($valid) { $customValue[$fieldName] = $value; } } } } $form->set('customGetValues', $customValue); $form->set('groupTree', $groupTree); }