本文整理汇总了PHP中CRM_Utils_System::explode方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_System::explode方法的具体用法?PHP CRM_Utils_System::explode怎么用?PHP CRM_Utils_System::explode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Utils_System
的用法示例。
在下文中一共展示了CRM_Utils_System::explode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setDefaultValues
/**
* Set the default form values
*
* @access protected
*
* @return array the default array reference
*/
function setDefaultValues()
{
$defaults = array();
$stateCountryMap = array();
foreach ($this->_fields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name'])) {
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
}
//CRM-5403
if (substr($name, 0, 14) === 'state_province' || substr($name, 0, 7) === 'country' || substr($name, 0, 6) === 'county') {
list($fieldName, $index) = CRM_Utils_System::explode('-', $name, 2);
if (!array_key_exists($index, $stateCountryMap)) {
$stateCountryMap[$index] = array();
}
$stateCountryMap[$index][$fieldName] = $name;
}
}
// also take care of state country widget
if (!empty($stateCountryMap)) {
CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap, $defaults);
}
//set default for country.
CRM_Core_BAO_UFGroup::setRegisterDefaults($this->_fields, $defaults);
// now fix all state country selectors
CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
return $defaults;
}
示例2: smarty_modifier_crmBtnType
/**
* Grab the button type from a passed button element 'name' by checking for reserved QF button type strings
*
* @param $btnName
*
* @internal param string $btnId
*
* @return string button type, one of: 'upload', 'next', 'back', 'cancel', 'refresh'
* 'submit', 'done', 'display', 'jump' 'process'
* @access public
*/
function smarty_modifier_crmBtnType($btnName)
{
// split the string into 5 or more
// button name are typically: '_qf_Contact_refresh' OR '_qf_Contact_refresh_dedupe'
// button type is always the 3rd element
// note the first _
$substr = CRM_Utils_System::explode('_', $btnName, 5);
return $substr[3];
}
示例3: smarty_modifier_crmBtnValidate
/**
* Based on the QF id, give this button a class 'validate' or 'cancel' which will be used by jQuery.validate
*
* @param string $btnName
*
* @return string
*
* @see smarty_modifier_crmBtnType
* @access public
*/
function smarty_modifier_crmBtnValidate($btnName)
{
// split the string into 5 or more
// button name are typically: '_qf_Contact_refresh' OR '_qf_Contact_refresh_dedupe'
// button type is always the 3rd element
// note the first _
$substr = CRM_Utils_System::explode('_', $btnName, 5);
if (in_array($substr[3], array('upload', 'next', 'submit', 'done', 'process'))) {
return 'validate';
}
return 'cancel';
}
示例4: formatProfileContactParams
/**
* Format profile contact parameters.
*
* @param array $params
* @param $fields
* @param int $contactID
* @param int $ufGroupId
* @param null $ctype
* @param bool $skipCustom
*
* @return array
*/
public static function formatProfileContactParams(&$params, &$fields, $contactID = NULL, $ufGroupId = NULL, $ctype = NULL, $skipCustom = FALSE)
{
$data = $contactDetails = array();
// get the contact details (hier)
if ($contactID) {
list($details, $options) = self::getHierContactDetails($contactID, $fields);
$contactDetails = $details[$contactID];
$data['contact_type'] = CRM_Utils_Array::value('contact_type', $contactDetails);
$data['contact_sub_type'] = CRM_Utils_Array::value('contact_sub_type', $contactDetails);
} else {
//we should get contact type only if contact
if ($ufGroupId) {
$data['contact_type'] = CRM_Core_BAO_UFField::getProfileType($ufGroupId);
//special case to handle profile with only contact fields
if ($data['contact_type'] == 'Contact') {
$data['contact_type'] = 'Individual';
} elseif (CRM_Contact_BAO_ContactType::isaSubType($data['contact_type'])) {
$data['contact_type'] = CRM_Contact_BAO_ContactType::getBasicType($data['contact_type']);
}
} elseif ($ctype) {
$data['contact_type'] = $ctype;
} else {
$data['contact_type'] = 'Individual';
}
}
//fix contact sub type CRM-5125
if (array_key_exists('contact_sub_type', $params) && !empty($params['contact_sub_type'])) {
$data['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, (array) $params['contact_sub_type']) . CRM_Core_DAO::VALUE_SEPARATOR;
} elseif (array_key_exists('contact_sub_type_hidden', $params) && !empty($params['contact_sub_type_hidden'])) {
// if profile was used, and had any subtype, we obtain it from there
$data['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, (array) $params['contact_sub_type_hidden']) . CRM_Core_DAO::VALUE_SEPARATOR;
}
if ($ctype == 'Organization') {
$data['organization_name'] = CRM_Utils_Array::value('organization_name', $contactDetails);
} elseif ($ctype == 'Household') {
$data['household_name'] = CRM_Utils_Array::value('household_name', $contactDetails);
}
$locationType = array();
$count = 1;
if ($contactID) {
//add contact id
$data['contact_id'] = $contactID;
$primaryLocationType = self::getPrimaryLocationType($contactID);
} else {
$defaultLocation = CRM_Core_BAO_LocationType::getDefault();
$defaultLocationId = $defaultLocation->id;
}
// get the billing location type
$locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
$billingLocationTypeId = array_search('Billing', $locationTypes);
$blocks = array('email', 'phone', 'im', 'openid');
$multiplFields = array('url');
// prevent overwritten of formatted array, reset all block from
// params if it is not in valid format (since import pass valid format)
foreach ($blocks as $blk) {
if (array_key_exists($blk, $params) && !is_array($params[$blk])) {
unset($params[$blk]);
}
}
$primaryPhoneLoc = NULL;
$session = CRM_Core_Session::singleton();
foreach ($params as $key => $value) {
$fieldName = $locTypeId = $typeId = NULL;
list($fieldName, $locTypeId, $typeId) = CRM_Utils_System::explode('-', $key, 3);
//store original location type id
$actualLocTypeId = $locTypeId;
if ($locTypeId == 'Primary') {
if ($contactID) {
if (in_array($fieldName, $blocks)) {
$locTypeId = self::getPrimaryLocationType($contactID, FALSE, $fieldName);
} else {
$locTypeId = self::getPrimaryLocationType($contactID, FALSE, 'address');
}
$primaryLocationType = $locTypeId;
} else {
$locTypeId = $defaultLocationId;
}
}
if (is_numeric($locTypeId) && !in_array($fieldName, $multiplFields) && substr($fieldName, 0, 7) != 'custom_') {
$index = $locTypeId;
if (is_numeric($typeId)) {
$index .= '-' . $typeId;
}
if (!in_array($index, $locationType)) {
$locationType[$count] = $index;
$count++;
}
$loc = CRM_Utils_Array::key($index, $locationType);
//.........这里部分代码省略.........
示例5: formRule
//.........这里部分代码省略.........
$exceptions = array($form->_session->get('userID'));
}
// for dialog mode we should always use fuzzy rule.
$ruleType = 'Unsupervised';
if ($form->_context == 'dialog') {
$ruleType = 'Supervised';
}
$dedupeParams['check_permission'] = FALSE;
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $ctype, $ruleType, $exceptions, $form->_ruleGroupID);
if ($ids) {
if ($form->_isUpdateDupe == 2) {
CRM_Core_Session::setStatus(ts('Note: this contact may be a duplicate of an existing record.'), ts('Possible Duplicate Detected'), 'alert');
} elseif ($form->_isUpdateDupe == 1) {
if (!$form->_id) {
$form->_id = $ids[0];
}
} else {
if ($form->_context == 'dialog') {
$contactLinks = CRM_Contact_BAO_Contact_Utils::formatContactIDSToLinks($ids, TRUE, TRUE);
$duplicateContactsLinks = '<div class="matching-contacts-found">';
$duplicateContactsLinks .= ts('One matching contact was found. ', array('count' => count($contactLinks['rows']), 'plural' => '%count matching contacts were found.<br />'));
if ($contactLinks['msg'] == 'view') {
$duplicateContactsLinks .= ts('You can View the existing contact.', array('count' => count($contactLinks['rows']), 'plural' => 'You can View the existing contacts.'));
} else {
$duplicateContactsLinks .= ts('You can View or Edit the existing contact.', array('count' => count($contactLinks['rows']), 'plural' => 'You can View or Edit the existing contacts.'));
}
$duplicateContactsLinks .= '</div>';
$duplicateContactsLinks .= '<table class="matching-contacts-actions">';
$row = '';
for ($i = 0; $i < count($contactLinks['rows']); $i++) {
$row .= ' <tr> ';
$row .= ' <td class="matching-contacts-name"> ';
$row .= $contactLinks['rows'][$i]['display_name'];
$row .= ' </td>';
$row .= ' <td class="matching-contacts-email"> ';
$row .= $contactLinks['rows'][$i]['primary_email'];
$row .= ' </td>';
$row .= ' <td class="action-items"> ';
$row .= $contactLinks['rows'][$i]['view'] . ' ';
$row .= $contactLinks['rows'][$i]['edit'];
$row .= ' </td>';
$row .= ' </tr> ';
}
$duplicateContactsLinks .= $row . '</table>';
$duplicateContactsLinks .= "If you're sure this record is not a duplicate, click the 'Save Matching Contact' button below.";
$errors['_qf_default'] = $duplicateContactsLinks;
// let smarty know that there are duplicates
$template = CRM_Core_Smarty::singleton();
$template->assign('isDuplicate', 1);
} else {
$errors['_qf_default'] = ts('A record already exists with the same information.');
}
}
}
}
foreach ($fields as $key => $value) {
list($fieldName, $locTypeId, $phoneTypeId) = CRM_Utils_System::explode('-', $key, 3);
if ($fieldName == 'state_province' && !empty($fields["country-{$locTypeId}"])) {
// Validate Country - State list
$countryId = $fields["country-{$locTypeId}"];
$stateProvinceId = $value;
if ($stateProvinceId && $countryId) {
$stateProvinceDAO = new CRM_Core_DAO_StateProvince();
$stateProvinceDAO->id = $stateProvinceId;
$stateProvinceDAO->find(TRUE);
if ($stateProvinceDAO->country_id != $countryId) {
// country mismatch hence display error
$stateProvinces = CRM_Core_PseudoConstant::stateProvince();
$countries = CRM_Core_PseudoConstant::country();
$errors[$key] = "State/Province " . $stateProvinces[$stateProvinceId] . " is not part of " . $countries[$countryId] . ". It belongs to " . $countries[$stateProvinceDAO->country_id] . ".";
}
}
}
if ($fieldName == 'county' && $fields["state_province-{$locTypeId}"]) {
// Validate County - State list
$stateProvinceId = $fields["state_province-{$locTypeId}"];
$countyId = $value;
if ($countyId && $stateProvinceId) {
$countyDAO = new CRM_Core_DAO_County();
$countyDAO->id = $countyId;
$countyDAO->find(TRUE);
if ($countyDAO->state_province_id != $stateProvinceId) {
// state province mismatch hence display error
$stateProvinces = CRM_Core_PseudoConstant::stateProvince();
$counties = CRM_Core_PseudoConstant::county();
$errors[$key] = "County " . $counties[$countyId] . " is not part of " . $stateProvinces[$stateProvinceId] . ". It belongs to " . $stateProvinces[$countyDAO->state_province_id] . ".";
}
}
}
}
foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
if ($greetingType = CRM_Utils_Array::value($greeting, $fields)) {
$customizedValue = CRM_Core_OptionGroup::getValue($greeting, 'Customized', 'name');
if ($customizedValue == $greetingType && empty($fields[$greeting . '_custom'])) {
$errors[$greeting . '_custom'] = ts('Custom %1 is a required field if %1 is of type Customized.', array(1 => ucwords(str_replace('_', ' ', $greeting))));
}
}
}
return empty($errors) ? TRUE : $errors;
}
示例6: trim
static function &makeArray($string)
{
$string = trim($string);
$values = explode("\n", $string);
$result = array();
foreach ($values as $value) {
list($n, $v) = CRM_Utils_System::explode('=', $value, 2);
if (!empty($v)) {
$result[trim($n)] = trim($v);
}
}
return $result;
}
示例7: array
/**
* returns all the rows in the given offset and rowCount
*
* @param enum $action the action being performed
* @param int $offset the row number to start from
* @param int $rowCount the number of rows to return
* @param string $sort the sql string that describes the sort order
* @param enum $output what should the result set include (web/email/csv)
*
* @return int the total number of rows for this action
*/
function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
{
$config = CRM_Core_Config::singleton();
if (($output == CRM_Core_Selector_Controller::EXPORT || $output == CRM_Core_Selector_Controller::SCREEN) && $this->_formValues['radio_ts'] == 'ts_sel') {
$includeContactIds = TRUE;
} else {
$includeContactIds = FALSE;
}
// note the formvalues were given by CRM_Contact_Form_Search to us
// and contain the search criteria (parameters)
// note that the default action is basic
if ($rowCount) {
$cacheKey = $this->buildPrevNextCache($sort);
$result = $this->_query->getCachedContacts($cacheKey, $offset, $rowCount, $includeContactIds);
} else {
$result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, $includeContactIds);
}
// process the result of the query
$rows = array();
$permissions = array(CRM_Core_Permission::getPermission());
if (CRM_Core_Permission::check('delete contacts')) {
$permissions[] = CRM_Core_Permission::DELETE;
}
$mask = CRM_Core_Action::mask($permissions);
// mask value to hide map link if there are not lat/long
$mapMask = $mask & 4095;
if ($this->_searchContext == 'smog') {
$gc = CRM_Core_SelectValues::groupContactStatus();
}
if ($this->_ufGroupID) {
$locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
$names = array();
static $skipFields = array('group', 'tag');
foreach ($this->_fields as $key => $field) {
if (!empty($field['in_selector']) && !in_array($key, $skipFields)) {
if (strpos($key, '-') !== FALSE) {
list($fieldName, $id, $type) = CRM_Utils_System::explode('-', $key, 3);
if ($id == 'Primary') {
$locationTypeName = 1;
} else {
$locationTypeName = CRM_Utils_Array::value($id, $locationTypes);
if (!$locationTypeName) {
continue;
}
}
$locationTypeName = str_replace(' ', '_', $locationTypeName);
if (in_array($fieldName, array('phone', 'im', 'email'))) {
if ($type) {
$names[] = "{$locationTypeName}-{$fieldName}-{$type}";
} else {
$names[] = "{$locationTypeName}-{$fieldName}";
}
} else {
$names[] = "{$locationTypeName}-{$fieldName}";
}
} else {
$names[] = $field['name'];
}
}
}
$names[] = "status";
} elseif (!empty($this->_returnProperties)) {
$names = self::makeProperties($this->_returnProperties);
} else {
$names = self::$_properties;
}
$multipleSelectFields = array('preferred_communication_method' => 1);
$links = self::links($this->_context, $this->_contextMenu, $this->_key);
//check explicitly added contact to a Smart Group.
$groupID = CRM_Utils_Array::key('1', $this->_formValues['group']);
$pseudoconstants = array();
// for CRM-3157 purposes
if (in_array('world_region', $names)) {
$pseudoconstants['world_region'] = array('dbName' => 'world_region_id', 'values' => CRM_Core_PseudoConstant::worldRegion());
}
$seenIDs = array();
while ($result->fetch()) {
$row = array();
$this->_query->convertToPseudoNames($result);
// the columns we are interested in
foreach ($names as $property) {
if ($property == 'status') {
continue;
}
if ($cfID = CRM_Core_BAO_CustomField::getKeyID($property)) {
$row[$property] = CRM_Core_BAO_CustomField::getDisplayValue($result->{$property}, $cfID, $this->_options, $result->contact_id);
} elseif ($multipleSelectFields && array_key_exists($property, $multipleSelectFields)) {
$key = $property;
$paramsNew = array($key => $result->{$property});
//.........这里部分代码省略.........
示例8: isErrorInCustomData
/**
* 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');
//.........这里部分代码省略.........
示例9: validChecksum
/**
* Make sure the checksum is valid for the passed in contactID.
*
* @param int $contactID
* @param string $inputCheck
* Checksum to match against.
*
* @return bool
* true if valid, else false
*/
public static function validChecksum($contactID, $inputCheck)
{
$input = CRM_Utils_System::explode('_', $inputCheck, 3);
$inputCS = CRM_Utils_Array::value(0, $input);
$inputTS = CRM_Utils_Array::value(1, $input);
$inputLF = CRM_Utils_Array::value(2, $input);
$check = self::generateChecksum($contactID, $inputTS, $inputLF);
if ($check != $inputCheck) {
return FALSE;
}
// no life limit for checksum
if ($inputLF == 'inf') {
return TRUE;
}
// checksum matches so now check timestamp
$now = time();
return $inputTS + $inputLF * 60 * 60 >= $now;
}
示例10: buildComponentForm
//.........这里部分代码省略.........
continue;
}
if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_values['honoree_profile_id'], 'is_active')) {
CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the selected honoree profile is either disabled or not found.'));
}
$profileContactType = CRM_Core_BAO_UFGroup::getContactType($form->_values['honoree_profile_id']);
$requiredProfileFields = array('Individual' => array('first_name', 'last_name'), 'Organization' => array('organization_name', 'email'), 'Household' => array('household_name', 'email'));
$validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($form->_values['honoree_profile_id'], $requiredProfileFields[$profileContactType]);
if (!$validProfile) {
CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the required fields of the selected honoree profile are disabled or doesn\'t exist.'));
}
foreach (array('honor_block_title', 'honor_block_text') as $name) {
$form->assign($name, $form->_values[$name]);
}
$softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
// radio button for Honor Type
foreach ($form->_values['soft_credit_types'] as $value) {
$honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value);
}
$form->addGroup($honorTypes, 'soft_credit_type_id', NULL)->setAttribute('allowClear', TRUE);
$honoreeProfileFields = CRM_Core_BAO_UFGroup::getFields($this->_values['honoree_profile_id'], FALSE, NULL, NULL, NULL, FALSE, NULL, TRUE, NULL, CRM_Core_Permission::CREATE);
$form->assign('honoreeProfileFields', $honoreeProfileFields);
// add the form elements
foreach ($honoreeProfileFields as $name => $field) {
// If soft credit type is not chosen then make omit requiredness from honoree profile fields
if (count($form->_submitValues) && empty($form->_submitValues['soft_credit_type_id']) && !empty($field['is_required'])) {
$field['is_required'] = FALSE;
}
CRM_Core_BAO_UFGroup::buildProfile($form, $field, CRM_Profile_Form::MODE_CREATE, NULL, FALSE, FALSE, NULL, 'honor');
}
} else {
if (empty($form->_values['onbehalf_profile_id'])) {
continue;
}
if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_values['onbehalf_profile_id'], 'is_active')) {
CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of an organization and the selected onbehalf profile is either disabled or not found.'));
}
$member = CRM_Member_BAO_Membership::getMembershipBlock($form->_id);
if (empty($member['is_active'])) {
$msg = ts('Mixed profile not allowed for on behalf of registration/sign up.');
$onBehalfProfile = CRM_Core_BAO_UFGroup::profileGroups($form->_values['onbehalf_profile_id']);
foreach (array('Individual', 'Organization', 'Household') as $contactType) {
if (in_array($contactType, $onBehalfProfile) && (in_array('Membership', $onBehalfProfile) || in_array('Contribution', $onBehalfProfile))) {
CRM_Core_Error::fatal($msg);
}
}
}
if ($contactID) {
// retrieve all permissioned organizations of contact $contactID
$organizations = CRM_Contact_BAO_Relationship::getPermissionedContacts($contactID, NULL, NULL, 'Organization');
if (count($organizations)) {
// Related org url - pass checksum if needed
$args = array('ufId' => $form->_values['onbehalf_profile_id'], 'cid' => '');
if (!empty($_GET['cs'])) {
$args = array('ufId' => $form->_values['onbehalf_profile_id'], 'uid' => $this->_contactID, 'cs' => $_GET['cs'], 'cid' => '');
}
$locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', $args, FALSE, NULL, FALSE);
$form->assign('locDataURL', $locDataURL);
}
if (count($organizations) > 0) {
$form->add('select', 'onbehalfof_id', '', CRM_Utils_Array::collect('name', $organizations));
$orgOptions = array(0 => ts('Select an existing organization'), 1 => ts('Enter a new organization'));
$form->addRadio('org_option', ts('options'), $orgOptions);
$form->setDefaults(array('org_option' => 0));
}
}
$form->assign('fieldSetTitle', ts('Organization Details'));
if (CRM_Utils_Array::value('is_for_organization', $form->_values)) {
if ($form->_values['is_for_organization'] == 2) {
$form->assign('onBehalfRequired', TRUE);
} else {
$form->addElement('checkbox', 'is_for_organization', $form->_values['for_organization'], NULL);
}
}
$profileFields = CRM_Core_BAO_UFGroup::getFields($form->_values['onbehalf_profile_id'], FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
$form->assign('onBehalfOfFields', $profileFields);
if (!empty($form->_submitValues['onbehalf'])) {
if (!empty($form->_submitValues['onbehalfof_id'])) {
$form->assign('submittedOnBehalf', $form->_submitValues['onbehalfof_id']);
}
$form->assign('submittedOnBehalfInfo', json_encode($form->_submitValues['onbehalf']));
}
$fieldTypes = array('Contact', 'Organization');
$contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
$fieldTypes = array_merge($fieldTypes, $contactSubType);
foreach ($profileFields as $name => $field) {
if (in_array($field['field_type'], $fieldTypes)) {
list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
if (in_array($prefixName, array('organization_name', 'email')) && empty($field['is_required'])) {
$field['is_required'] = 1;
}
if (count($form->_submitValues) && empty($form->_submitValues['is_for_organization']) && $form->_values['is_for_organization'] == 1 && !empty($field['is_required'])) {
$field['is_required'] = FALSE;
}
CRM_Core_BAO_UFGroup::buildProfile($form, $field, NULL, NULL, FALSE, 'onbehalf', NULL, 'onbehalf');
}
}
}
}
}
示例11: getFromTo
/**
* Get values for from and to for date ranges.
*
* @param bool $relative
* @param string $from
* @param string $to
* @param string $fromTime
* @param string $toTime
*
* @return array
*/
public function getFromTo($relative, $from, $to, $fromTime = NULL, $toTime = NULL)
{
if (empty($toTime)) {
$toTime = '235959';
}
//FIX ME not working for relative
if ($relative) {
list($term, $unit) = CRM_Utils_System::explode('.', $relative, 2);
$dateRange = CRM_Utils_Date::relativeToAbsolute($term, $unit);
$from = substr($dateRange['from'], 0, 8);
//Take only Date Part, Sometime Time part is also present in 'to'
$to = substr($dateRange['to'], 0, 8);
}
$from = CRM_Utils_Date::processDate($from, $fromTime);
$to = CRM_Utils_Date::processDate($to, $toTime);
return array($from, $to);
}
示例12: buildCustom
/**
* Build the petition profile form.
*
* @param int $id
* @param string $name
* @param bool $viewOnly
*/
public function buildCustom($id, $name, $viewOnly = FALSE)
{
if ($id) {
$session = CRM_Core_Session::singleton();
$this->assign("petition", $this->petition);
//$contactID = $this->_contactId;
$contactID = NULL;
$this->assign('contact_id', $this->_contactId);
$fields = NULL;
// TODO: contactID is never set (commented above)
if ($contactID) {
if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
$fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
}
} else {
$fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
}
if ($fields) {
$this->assign($name, $fields);
$addCaptcha = FALSE;
foreach ($fields as $key => $field) {
if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
// ignore file upload fields
continue;
}
// if state or country in the profile, create map
list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
$this->_fields[$key] = $field;
// CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
if ($field['add_captcha'] && !$this->_contactId) {
$addCaptcha = TRUE;
}
}
if ($addCaptcha && !$viewOnly) {
$captcha = CRM_Utils_ReCAPTCHA::singleton();
$captcha->add($this);
$this->assign("isCaptcha", TRUE);
}
}
}
}
示例13: getMenuName
/**
* Get Menu name
*
* @param $value
* @param $skipMenuItems
* @return bool|string
*/
static function getMenuName(&$value, &$skipMenuItems)
{
// we need to localise the menu labels (CRM-5456) and don’t
// want to use ts() as it would throw the ts-extractor off
$i18n = CRM_Core_I18n::singleton();
$name = $i18n->crm_translate($value['attributes']['label'], array('context' => 'menu'));
$url = $value['attributes']['url'];
$permission = $value['attributes']['permission'];
$operator = $value['attributes']['operator'];
$parentID = $value['attributes']['parentID'];
$navID = $value['attributes']['navID'];
$active = $value['attributes']['active'];
$menuName = $value['attributes']['name'];
$target = CRM_Utils_Array::value('target', $value['attributes']);
if (in_array($parentID, $skipMenuItems) || !$active) {
$skipMenuItems[] = $navID;
return FALSE;
}
//we need to check core view/edit or supported acls.
if (in_array($menuName, array('Search...', 'Contacts'))) {
if (!CRM_Core_Permission::giveMeAllACLs()) {
$skipMenuItems[] = $navID;
return FALSE;
}
}
$config = CRM_Core_Config::singleton();
$makeLink = FALSE;
if (isset($url) && $url) {
if (substr($url, 0, 4) === 'http') {
$url = $url;
} else {
//CRM-7656 --make sure to separate out url path from url params,
//as we'r going to validate url path across cross-site scripting.
$urlParam = CRM_Utils_System::explode('&', str_replace('?', '&', $url), 2);
$url = CRM_Utils_System::url($urlParam[0], $urlParam[1], FALSE, NULL, TRUE);
}
$makeLink = TRUE;
}
static $allComponents;
if (!$allComponents) {
$allComponents = CRM_Core_Component::getNames();
}
if (isset($permission) && $permission) {
$permissions = explode(',', $permission);
$hasPermission = FALSE;
foreach ($permissions as $key) {
$key = trim($key);
$showItem = TRUE;
//get the component name from permission.
$componentName = CRM_Core_Permission::getComponentName($key);
if ($componentName) {
if (!in_array($componentName, $config->enableComponents) || !CRM_Core_Permission::check($key)) {
$showItem = FALSE;
if ($operator == 'AND') {
$skipMenuItems[] = $navID;
return $showItem;
}
} else {
$hasPermission = TRUE;
}
} elseif (!CRM_Core_Permission::check($key)) {
$showItem = FALSE;
if ($operator == 'AND') {
$skipMenuItems[] = $navID;
return $showItem;
}
} else {
$hasPermission = TRUE;
}
}
if (!$showItem && !$hasPermission) {
$skipMenuItems[] = $navID;
return FALSE;
}
}
if ($makeLink) {
if ($target) {
$name = "<a href=\"{$url}\" target=\"{$target}\">{$name}</a>";
} else {
$name = "<a href=\"{$url}\">{$name}</a>";
}
}
return $name;
}
示例14: trim
/**
* @param $args
*
* @return array
*/
public static function &buildFormValues($args)
{
$args = trim($args);
$values = explode("\n", $args);
$formValues = array();
foreach ($values as $value) {
list($n, $v) = CRM_Utils_System::explode('=', $value, 2);
if (!empty($v)) {
$formValues[$n] = $v;
}
}
return $formValues;
}
示例15: setProfileDefaults
/**
* Function to set profile defaults
*
* @params int $contactId contact id
* @params array $fields associative array of fields
* @params array $defaults defaults array
* @params boolean $singleProfile true for single profile else false(batch update)
* @params int $componentId id for specific components like contribute, event etc
*
* @return null
* @static
* @access public
*/
static function setProfileDefaults($contactId, &$fields, &$defaults, $singleProfile = true, $componentId = null, $component = null)
{
if (!$componentId) {
//get the contact details
require_once 'CRM/Contact/BAO/Contact.php';
list($contactDetails, $options) = CRM_Contact_BAO_Contact::getHierContactDetails($contactId, $fields);
$details = $contactDetails[$contactId];
require_once 'CRM/Contact/Form/Edit/TagsAndGroups.php';
//start of code to set the default values
foreach ($fields as $name => $field) {
//set the field name depending upon the profile mode(single/batch)
if ($singleProfile) {
$fldName = $name;
} else {
$fldName = "field[{$contactId}][{$name}]";
}
if ($name == 'group') {
CRM_Contact_Form_Edit_TagsAndGroups::setDefaults($contactId, $defaults, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, $fldName);
}
if ($name == 'tag') {
CRM_Contact_Form_Edit_TagsAndGroups::setDefaults($contactId, $defaults, CRM_Contact_Form_Edit_TagsAndGroups::TAG, $fldName);
}
if (CRM_Utils_Array::value($name, $details) || isset($details[$name])) {
//to handle custom data (checkbox) to be written
// to handle gender / suffix / prefix / greeting_type
if ($name == 'gender') {
$defaults[$fldName] = $details['gender_id'];
} else {
if ($name == 'individual_prefix') {
$defaults[$fldName] = $details['individual_prefix_id'];
} else {
if ($name == 'individual_suffix') {
$defaults[$fldName] = $details['individual_suffix_id'];
} else {
if ($name == 'birth_date' || $name == 'deceased_date') {
list($defaults[$fldName]) = CRM_Utils_Date::setDateDefaults($details[$name], 'birth');
} else {
if ($name == 'email_greeting') {
$defaults[$fldName] = $details['email_greeting_id'];
$defaults['email_greeting_custom'] = $details['email_greeting_custom'];
} else {
if ($name == 'postal_greeting') {
$defaults[$fldName] = $details['postal_greeting_id'];
$defaults['postal_greeting_custom'] = $details['postal_greeting_custom'];
} else {
if ($name == 'addressee') {
$defaults[$fldName] = $details['addressee_id'];
$defaults['addressee_custom'] = $details['addressee_custom'];
} else {
if ($name == 'preferred_communication_method') {
$v = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $details[$name]);
foreach ($v as $item) {
if ($item) {
$defaults[$fldName . "[{$item}]"] = 1;
}
}
} else {
if ($name == 'world_region') {
$defaults[$fldName] = $details['worldregion_id'];
} else {
if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($name)) {
//fix for custom fields
$customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('Individual', $values));
// hack to add custom data for components
$components = array("Contribution", "Participant", "Membership");
foreach ($components as $value) {
$customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFieldsForImport($value));
}
switch ($customFields[$customFieldId]['html_type']) {
case 'Multi-Select State/Province':
case 'Multi-Select Country':
case 'AdvMulti-Select':
case 'Multi-Select':
$v = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $details[$name]);
foreach ($v as $item) {
if ($item) {
$defaults[$fldName][$item] = $item;
}
}
break;
case 'CheckBox':
$v = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $details[$name]);
foreach ($v as $item) {
if ($item) {
$defaults[$fldName][$item] = 1;
// seems like we need this for QF style checkboxes in profile where its multiindexed
// CRM-2969
//.........这里部分代码省略.........