/** * Build the form object. * * @return void */ public function buildQuickForm() { // Register 'contact_1' model $entities = array(); $entities[] = array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel'); $allowCoreTypes = array_merge(array('Contact', 'Individual'), CRM_Contact_BAO_ContactType::subTypes('Individual')); $allowSubTypes = array(); // Register 'contribution_1' $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'financial_type_id'); $allowCoreTypes[] = 'Contribution'; //CRM-15427 $allowSubTypes['ContributionType'] = array($financialTypeId); $entities[] = array('entity_name' => 'contribution_1', 'entity_type' => 'ContributionModel', 'entity_sub_type' => '*'); // If applicable, register 'membership_1' $member = CRM_Member_BAO_Membership::getMembershipBlock($this->_id); if ($member && $member['is_active']) { //CRM-15427 $entities[] = array('entity_name' => 'membership_1', 'entity_type' => 'MembershipModel', 'entity_sub_type' => '*'); $allowCoreTypes[] = 'Membership'; $allowSubTypes['MembershipType'] = explode(',', $member['membership_types']); } //CRM-15427 $this->addProfileSelector('custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $entities, TRUE); $this->addProfileSelector('custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $entities, TRUE); $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Custom', 'formRule'), $this->_id); parent::buildQuickForm(); }
/** * Function to actually build the form * * @return void * @access public */ public function buildQuickForm() { require_once "CRM/Core/BAO/UFGroup.php"; require_once "CRM/Contact/BAO/ContactType.php"; $types = array_merge(array('Contact', 'Individual', 'Contribution', 'Membership'), CRM_Contact_BAO_ContactType::subTypes('Individual')); $profiles = CRM_Core_BAO_UFGroup::getProfiles($types); if (empty($profiles)) { $this->assign('noProfile', true); } $this->add('select', 'custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), array('' => ts('- select -')) + $profiles); $this->add('select', 'custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), array('' => ts('- select -')) + $profiles); $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Custom', 'formRule'), $this->_id); parent::buildQuickForm(); }
/** * Function to actually build the form * * @return void * @access public */ public function buildQuickForm() { $types = array_merge(array('Contact', 'Individual', 'Contribution', 'Membership'), CRM_Contact_BAO_ContactType::subTypes('Individual')); $profiles = CRM_Core_BAO_UFGroup::getProfiles($types); $excludeTypes = array('Organization', 'Household', 'Participant', 'Activity'); $excludeProfiles = CRM_Core_BAO_UFGroup::getProfiles($excludeTypes); foreach ($excludeProfiles as $key => $value) { if (array_key_exists($key, $profiles)) { unset($profiles[$key]); } } if (empty($profiles)) { $this->assign('noProfile', TRUE); } $this->add('select', 'custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), array('' => ts('- select -')) + $profiles); $this->add('select', 'custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), array('' => ts('- select -')) + $profiles); $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Custom', 'formRule'), $this->_id); parent::buildQuickForm(); }
/** * Implementation of hook_civicrm_install * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install */ function hrjobcontract_civicrm_install() { $cType = CRM_Contact_BAO_ContactType::basicTypePairs(false, 'id'); $org_id = array_search('Organization', $cType); $sub_type_name = array('Health Insurance Provider', 'Life Insurance Provider'); $orgSubType = CRM_Contact_BAO_ContactType::subTypes('Organization', true); $orgSubType = CRM_Contact_BAO_ContactType::subTypeInfo('Organization'); $params['parent_id'] = $org_id; $params['is_active'] = 1; if ($org_id) { foreach ($sub_type_name as $sub_type_name) { $subTypeName = ucfirst(CRM_Utils_String::munge($sub_type_name)); $subID = array_key_exists($subTypeName, $orgSubType); if (!$subID) { $params['name'] = $subTypeName; $params['label'] = $sub_type_name; CRM_Contact_BAO_ContactType::add($params); } elseif ($subID && $orgSubType[$subTypeName]['is_active'] == 0) { CRM_Contact_BAO_ContactType::setIsActive($orgSubType[$subTypeName]['id'], 1); } } } // Add Job Contract top menu $jobContractNavigation = new CRM_Core_DAO_Navigation(); $jobContractNavigation->name = 'job_contracts'; $jobContractNavigationResult = $jobContractNavigation->find(); if (!$jobContractNavigationResult) { $contactsWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Contacts', 'weight', 'name'); $jobContractNavigation = new CRM_Core_DAO_Navigation(); $params = array('domain_id' => CRM_Core_Config::domainID(), 'label' => ts('Job Contracts'), 'name' => 'job_contracts', 'url' => null, 'operator' => null, 'weight' => $contactsWeight + 1, 'is_active' => 1); $jobContractNavigation->copyValues($params); $jobContractNavigation->save(); $jobContractMenuTree = array(array('label' => ts('Import / Export'), 'name' => 'import_export_job_contracts')); foreach ($jobContractMenuTree as $key => $menuItems) { $menuItems['is_active'] = 1; $menuItems['parent_id'] = $jobContractNavigation->id; $menuItems['weight'] = $key; CRM_Core_BAO_Navigation::add($menuItems); } } return _hrjobcontract_civix_civicrm_install(); }
/** * Implementation of hook_civicrm_install */ function hrjob_civicrm_install() { $cType = CRM_Contact_BAO_ContactType::basicTypePairs(false, 'id'); $org_id = array_search('Organization', $cType); $sub_type_name = array('Health Insurance Provider', 'Life Insurance Provider'); $orgSubType = CRM_Contact_BAO_ContactType::subTypes('Organization', true); $orgSubType = CRM_Contact_BAO_ContactType::subTypeInfo('Organization'); $params['parent_id'] = $org_id; $params['is_active'] = 1; if ($org_id) { foreach ($sub_type_name as $sub_type_name) { $subTypeName = ucfirst(CRM_Utils_String::munge($sub_type_name)); $subID = array_key_exists($subTypeName, $orgSubType); if (!$subID) { $params['name'] = $subTypeName; $params['label'] = $sub_type_name; CRM_Contact_BAO_ContactType::add($params); } elseif ($subID && $orgSubType[$subTypeName]['is_active'] == 0) { CRM_Contact_BAO_ContactType::setIsActive($orgSubType[$subTypeName]['id'], 1); } } } //Add job import navigation menu $weight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Import Contacts', 'weight', 'name'); $contactNavId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Contacts', 'id', 'name'); $administerNavId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Dropdown Options', 'id', 'name'); $importJobNavigation = new CRM_Core_DAO_Navigation(); $params = array('domain_id' => CRM_Core_Config::domainID(), 'label' => ts('Import Jobs'), 'name' => 'jobImport', 'url' => null, 'parent_id' => $contactNavId, 'weight' => $weight + 1, 'permission' => 'access HRJobs', 'separator' => 1, 'is_active' => 1); $importJobNavigation->copyValues($params); $importJobNavigation->save(); $importJobMenuTree = array(array('label' => ts('Hours Types'), 'name' => 'hoursType', 'url' => 'civicrm/hour/editoption', 'permission' => 'administer CiviCRM', 'parent_id' => $administerNavId)); foreach ($importJobMenuTree as $key => $menuItems) { $menuItems['is_active'] = 1; CRM_Core_BAO_Navigation::add($menuItems); } CRM_Core_BAO_Navigation::resetNavigation(); return _hrjob_civix_civicrm_install(); }
function buildQuickForm() { /** * * id * name * description * require_login * is_active * */ $this->assign('wid', $this->_wid); // add form elements $this->add('text', 'name', ts('Name'), array("maxlength" => 255, "size" => 45), true); $this->addRule('name', ts('You must supply a name for this Workflow'), 'required'); $this->add('textarea', 'description', ts('Description'), array("rows" => 3, "cols" => 80)); $entities = array(); $entities[] = array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel'); $allowCoreTypes = array_merge(array('Contact', 'Individual'), CRM_Contact_BAO_ContactType::subTypes('Individual')); $allowSubTypes = array(); $this->addProfileSelector('login_form_id', ts('Login Profile'), $allowCoreTypes, $allowSubTypes, $entities); /* $this->add( 'select', 'login_form_id', ts('Login Profile'), array('' => ts('- select profile -')) + $profiles, false ); */ $this->add('checkbox', 'require_login', ts('Require Login')); $this->addElement('checkbox', 'is_active', ts('Is this workflow active?')); $this->addButtons(array(array('type' => 'submit', 'name' => ts('Submit'), 'isDefault' => TRUE))); // export form elements $this->assign('elementNames', $this->getRenderableElementNames()); parent::buildQuickForm(); }
/** * Class constructor. * * Takes in a set of custom field ids andsets up the data structures to * generate a query * * @param array $ids * The set of custom field ids. * * @param bool $contactSearch * @param array $locationSpecificFields */ public function __construct($ids, $contactSearch = FALSE, $locationSpecificFields = array()) { $this->_ids =& $ids; $this->_locationSpecificCustomFields = $locationSpecificFields; $this->_select = array(); $this->_element = array(); $this->_tables = array(); $this->_whereTables = array(); $this->_where = array(); $this->_qill = array(); $this->_options = array(); $this->_fields = array(); $this->_contactSearch = $contactSearch; if (empty($this->_ids)) { return; } // initialize the field array $tmpArray = array_keys($this->_ids); $idString = implode(',', $tmpArray); $query = "\nSELECT f.id, f.label, f.data_type,\n f.html_type, f.is_search_range,\n f.option_group_id, f.custom_group_id,\n f.column_name, g.table_name,\n f.date_format,f.time_format\n FROM civicrm_custom_field f,\n civicrm_custom_group g\n WHERE f.custom_group_id = g.id\n AND g.is_active = 1\n AND f.is_active = 1\n AND f.id IN ( {$idString} )"; $dao = CRM_Core_DAO::executeQuery($query); while ($dao->fetch()) { // get the group dao to figure which class this custom field extends $extends = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $dao->custom_group_id, 'extends'); if (array_key_exists($extends, self::$extendsMap)) { $extendsTable = self::$extendsMap[$extends]; } elseif (in_array($extends, CRM_Contact_BAO_ContactType::subTypes())) { // if $extends is a subtype, refer contact table $extendsTable = self::$extendsMap['Contact']; } $this->_fields[$dao->id] = array('id' => $dao->id, 'label' => $dao->label, 'extends' => $extendsTable, 'data_type' => $dao->data_type, 'html_type' => $dao->html_type, 'is_search_range' => $dao->is_search_range, 'column_name' => $dao->column_name, 'table_name' => $dao->table_name, 'option_group_id' => $dao->option_group_id); // store it in the options cache to make things easier // during option lookup $this->_options[$dao->id] = array(); $this->_options[$dao->id]['attributes'] = array('label' => $dao->label, 'data_type' => $dao->data_type, 'html_type' => $dao->html_type); $optionGroupID = NULL; $htmlTypes = array('CheckBox', 'Radio', 'Select', 'Multi-Select', 'AdvMulti-Select', 'Autocomplete-Select'); if (in_array($dao->html_type, $htmlTypes) && $dao->data_type != 'ContactReference') { if ($dao->option_group_id) { $optionGroupID = $dao->option_group_id; } elseif ($dao->data_type != 'Boolean') { $errorMessage = ts("The custom field %1 is corrupt. Please delete and re-build the field", array(1 => $dao->label)); CRM_Core_Error::fatal($errorMessage); } } elseif ($dao->html_type == 'Select Date') { $this->_options[$dao->id]['attributes']['date_format'] = $dao->date_format; $this->_options[$dao->id]['attributes']['time_format'] = $dao->time_format; } // build the cache for custom values with options (label => value) if ($optionGroupID != NULL) { $query = "\nSELECT label, value\n FROM civicrm_option_value\n WHERE option_group_id = {$optionGroupID}\n"; $option = CRM_Core_DAO::executeQuery($query); while ($option->fetch()) { $dataType = $this->_fields[$dao->id]['data_type']; if ($dataType == 'Int' || $dataType == 'Float') { $num = round($option->value, 2); $this->_options[$dao->id]["{$num}"] = $option->label; } else { $this->_options[$dao->id][$option->value] = $option->label; } } $options = $this->_options[$dao->id]; //unset attributes to avoid confussion unset($options['attributes']); CRM_Utils_Hook::customFieldOptions($dao->id, $options, FALSE); } } }
/** * Format custom fields before inserting. * * @param int $customFieldId * Custom field id. * @param array $customFormatted * Formatted array. * @param mix $value * Value of custom field. * @param string $customFieldExtend * Custom field extends. * @param int $customValueId * Custom option value id. * @param int $entityId * Entity id (contribution, membership...). * @param bool $inline * Consider inline custom groups only. * @param bool $checkPermission * If false, do not include permissioning clause. * @param bool $includeViewOnly * If true, fields marked 'View Only' are included. Required for APIv3. * * @return array|NULL * formatted custom field array */ public static function formatCustomField($customFieldId, &$customFormatted, $value, $customFieldExtend, $customValueId = NULL, $entityId = NULL, $inline = FALSE, $checkPermission = TRUE, $includeViewOnly = FALSE) { //get the custom fields for the entity //subtype and basic type $customDataSubType = NULL; if ($customFieldExtend) { // This is the case when getFieldsForImport() requires fields // of subtype and its parent.CRM-5143 // CRM-16065 - Custom field set data not being saved if contact has more than one contact sub type $customDataSubType = array_intersect(CRM_Contact_BAO_ContactType::subTypes(), (array) $customFieldExtend); if (!empty($customDataSubType) && is_array($customDataSubType)) { $customFieldExtend = CRM_Contact_BAO_ContactType::getBasicType($customDataSubType); if (is_array($customFieldExtend)) { $customFieldExtend = array_unique(array_values($customFieldExtend)); } } } $customFields = CRM_Core_BAO_CustomField::getFields($customFieldExtend, FALSE, $inline, $customDataSubType, NULL, FALSE, FALSE, $checkPermission); if (!array_key_exists($customFieldId, $customFields)) { return NULL; } // return if field is a 'code' field if (!$includeViewOnly && !empty($customFields[$customFieldId]['is_view'])) { return NULL; } list($tableName, $columnName, $groupID) = self::getTableColumnGroup($customFieldId); if (!$customValueId && !$customFields[$customFieldId]['is_multiple'] && $entityId) { $query = "\nSELECT id\n FROM {$tableName}\n WHERE entity_id={$entityId}"; $customValueId = CRM_Core_DAO::singleValueQuery($query); } //fix checkbox, now check box always submits values if ($customFields[$customFieldId]['html_type'] == 'CheckBox') { if ($value) { // Note that only during merge this is not an array, and you can directly use value if (is_array($value)) { $selectedValues = array(); foreach ($value as $selId => $val) { if ($val) { $selectedValues[] = $selId; } } if (!empty($selectedValues)) { $value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $selectedValues) . CRM_Core_DAO::VALUE_SEPARATOR; } else { $value = ''; } } } } if ($customFields[$customFieldId]['html_type'] == 'Multi-Select' || $customFields[$customFieldId]['html_type'] == 'AdvMulti-Select') { if ($value) { // Note that only during merge this is not an array, // and you can directly use value, CRM-4385 if (is_array($value)) { $value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_values($value)) . CRM_Core_DAO::VALUE_SEPARATOR; } } else { $value = ''; } } if (($customFields[$customFieldId]['html_type'] == 'Multi-Select' || $customFields[$customFieldId]['html_type'] == 'AdvMulti-Select' || $customFields[$customFieldId]['html_type'] == 'CheckBox') && $customFields[$customFieldId]['data_type'] == 'String' && !empty($customFields[$customFieldId]['text_length']) && !empty($value)) { // lets make sure that value is less than the length, else we'll // be losing some data, CRM-7481 if (strlen($value) >= $customFields[$customFieldId]['text_length']) { // need to do a few things here // 1. lets find a new length $newLength = $customFields[$customFieldId]['text_length']; $minLength = strlen($value); while ($newLength < $minLength) { $newLength = $newLength * 2; } // set the custom field meta data to have a length larger than value // alter the custom value table column to match this length CRM_Core_BAO_SchemaHandler::alterFieldLength($customFieldId, $tableName, $columnName, $newLength); } } $date = NULL; if ($customFields[$customFieldId]['data_type'] == 'Date') { if (!CRM_Utils_System::isNull($value)) { $format = $customFields[$customFieldId]['date_format']; $date = CRM_Utils_Date::processDate($value, NULL, FALSE, 'YmdHis', $format); } $value = $date; } if ($customFields[$customFieldId]['data_type'] == 'Float' || $customFields[$customFieldId]['data_type'] == 'Money') { if (!$value) { $value = 0; } if ($customFields[$customFieldId]['data_type'] == 'Money') { $value = CRM_Utils_Rule::cleanMoney($value); } } if (($customFields[$customFieldId]['data_type'] == 'StateProvince' || $customFields[$customFieldId]['data_type'] == 'Country') && empty($value)) { // CRM-3415 $value = 0; } $fileId = NULL; if ($customFields[$customFieldId]['data_type'] == 'File') { if (empty($value)) { return; } $config = CRM_Core_Config::singleton(); $fName = $value['name']; $mimeType = $value['type']; $filename = pathinfo($fName, PATHINFO_BASENAME); // rename this file to go into the secure directory if (!rename($fName, $config->customFileUploadDir . $filename)) { CRM_Core_Error::statusBounce(ts('Could not move custom file to custom upload directory')); } if ($customValueId) { $query = "\nSELECT {$columnName}\n FROM {$tableName}\n WHERE id = %1"; $params = array(1 => array($customValueId, 'Integer')); $fileId = CRM_Core_DAO::singleValueQuery($query, $params); } $fileDAO = new CRM_Core_DAO_File(); if ($fileId) { $fileDAO->id = $fileId; } $fileDAO->uri = $filename; $fileDAO->mime_type = $mimeType; $fileDAO->upload_date = date('Ymdhis'); $fileDAO->save(); $fileId = $fileDAO->id; $value = $filename; } if (!is_array($customFormatted)) { $customFormatted = array(); } if (!array_key_exists($customFieldId, $customFormatted)) { $customFormatted[$customFieldId] = array(); } $index = -1; if ($customValueId) { $index = $customValueId; } if (!array_key_exists($index, $customFormatted[$customFieldId])) { $customFormatted[$customFieldId][$index] = array(); } $customFormatted[$customFieldId][$index] = array('id' => $customValueId > 0 ? $customValueId : NULL, 'value' => $value, 'type' => $customFields[$customFieldId]['data_type'], 'custom_field_id' => $customFieldId, 'custom_group_id' => $groupID, 'table_name' => $tableName, 'column_name' => $columnName, 'file_id' => $fileId, 'is_multiple' => $customFields[$customFieldId]['is_multiple']); //we need to sort so that custom fields are created in the order of entry krsort($customFormatted[$customFieldId]); return $customFormatted; }
/** * Class constructor. * * Takes in a set of custom field ids andsets up the data structures to * generate a query * * @param array $ids * The set of custom field ids. * * @param bool $contactSearch * @param array $locationSpecificFields */ public function __construct($ids, $contactSearch = FALSE, $locationSpecificFields = array()) { $this->_ids =& $ids; $this->_locationSpecificCustomFields = $locationSpecificFields; $this->_select = array(); $this->_element = array(); $this->_tables = array(); $this->_whereTables = array(); $this->_where = array(); $this->_qill = array(); $this->_options = array(); $this->_fields = array(); $this->_contactSearch = $contactSearch; if (empty($this->_ids)) { return; } // initialize the field array $tmpArray = array_keys($this->_ids); $idString = implode(',', $tmpArray); $query = "\nSELECT f.id, f.label, f.data_type,\n f.html_type, f.is_search_range,\n f.option_group_id, f.custom_group_id,\n f.column_name, g.table_name,\n f.date_format,f.time_format\n FROM civicrm_custom_field f,\n civicrm_custom_group g\n WHERE f.custom_group_id = g.id\n AND g.is_active = 1\n AND f.is_active = 1\n AND f.id IN ( {$idString} )"; $dao = CRM_Core_DAO::executeQuery($query); while ($dao->fetch()) { // get the group dao to figure which class this custom field extends $extends = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $dao->custom_group_id, 'extends'); if (array_key_exists($extends, self::$extendsMap)) { $extendsTable = self::$extendsMap[$extends]; } elseif (in_array($extends, CRM_Contact_BAO_ContactType::subTypes())) { // if $extends is a subtype, refer contact table $extendsTable = self::$extendsMap['Contact']; } $this->_fields[$dao->id] = array('id' => $dao->id, 'label' => $dao->label, 'extends' => $extendsTable, 'data_type' => $dao->data_type, 'html_type' => $dao->html_type, 'is_search_range' => $dao->is_search_range, 'column_name' => $dao->column_name, 'table_name' => $dao->table_name, 'option_group_id' => $dao->option_group_id); // Deprecated (and poorly named) cache of field attributes $this->_options[$dao->id] = array('attributes' => array('label' => $dao->label, 'data_type' => $dao->data_type, 'html_type' => $dao->html_type)); $options = CRM_Core_PseudoConstant::get('CRM_Core_BAO_CustomField', 'custom_' . $dao->id, array(), 'search'); if ($options) { $this->_options[$dao->id] += $options; } if ($dao->html_type == 'Select Date') { $this->_options[$dao->id]['attributes']['date_format'] = $dao->date_format; $this->_options[$dao->id]['attributes']['time_format'] = $dao->time_format; } } }
/** * Format custom fields before inserting * * @param int $customFieldId custom field id * @param array $customFormatted formatted array * @param mix $value value of custom field * @param string $customFieldExtend custom field extends * @param int $customValueId custom option value id * @param int $entityId entity id (contribution, membership...) * * @return array $customFormatted formatted custom field array * @static */ static function formatCustomField($customFieldId, &$customFormatted, $value, $customFieldExtend, $customValueId = null, $entityId = null, $inline = false) { //get the custom fields for the entity //subtype and basic type $customDataSubType = null; if (in_array($customFieldExtend, CRM_Contact_BAO_ContactType::subTypes())) { // This is the case when getFieldsForImport() requires fields // of subtype and its parent.CRM-5143 $customDataSubType = $customFieldExtend; $customFieldExtend = CRM_Contact_BAO_ContactType::getBasicType($customDataSubType); } $customFields = CRM_Core_BAO_CustomField::getFields($customFieldExtend, false, $inline, $customDataSubType); if (!array_key_exists($customFieldId, $customFields)) { return; } // return if field is a 'code' field if (CRM_Utils_Array::value('is_view', $customFields[$customFieldId])) { return; } list($tableName, $columnName, $groupID) = self::getTableColumnGroup($customFieldId); if (is_array($customFieldExtend)) { $customFieldExtend = $customFieldExtend[0]; } if (!$customValueId && !$customFields[$customFieldId]['is_multiple'] && $entityId) { //get the entity table for the custom field require_once "CRM/Core/BAO/CustomQuery.php"; $entityTable = CRM_Core_BAO_CustomQuery::$extendsMap[$customFieldExtend]; $query = "\nSELECT id \n FROM {$tableName}\n WHERE entity_id={$entityId}"; $customValueId = CRM_Core_DAO::singleValueQuery($query); } //fix checkbox, now check box always submits values if ($customFields[$customFieldId]['html_type'] == 'CheckBox') { if ($value) { // Note that only during merge this is not an array, and you can directly use value if (is_array($value)) { $selectedValues = null; foreach ($value as $selId => $val) { if ($val) { $selectedValues .= $selId . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR; } } if ($selectedValues) { $value = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . $selectedValues; } else { $value = ''; } } } } if ($customFields[$customFieldId]['html_type'] == 'Multi-Select' || $customFields[$customFieldId]['html_type'] == 'AdvMulti-Select') { if ($value) { // Note that only during merge this is not an array, // and you can directly use value, CRM-4385 if (is_array($value)) { $value = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, array_values($value)) . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR; } } else { $value = ''; } } $date = null; if ($customFields[$customFieldId]['data_type'] == 'Date') { if (!CRM_Utils_System::isNull($value)) { $format = $customFields[$customFieldId]['date_format']; if (in_array($format, array('dd-mm', 'mm/dd'))) { $dateTimeArray = explode(' ', $value); $separator = '/'; if ($format == 'dd-mm') { $separator = '-'; } $value = $dateTimeArray[0] . $separator . '1902'; if (array_key_exists(1, $dateTimeArray)) { $value .= ' ' . $dateTimeArray[1]; } } $date = CRM_Utils_Date::processDate($value); } $value = $date; } if ($customFields[$customFieldId]['data_type'] == 'Float' || $customFields[$customFieldId]['data_type'] == 'Money') { if (!$value) { $value = 0; } if ($customFields[$customFieldId]['data_type'] == 'Money') { require_once 'CRM/Utils/Rule.php'; $value = CRM_Utils_Rule::cleanMoney($value); } } if (($customFields[$customFieldId]['data_type'] == 'StateProvince' || $customFields[$customFieldId]['data_type'] == 'Country') && empty($value)) { // CRM-3415 $value = 0; } $fileId = null; if ($customFields[$customFieldId]['data_type'] == 'File') { if (empty($value)) { return; } require_once 'CRM/Core/DAO/File.php'; $config =& CRM_Core_Config::singleton(); $fName = $value['name']; $mimeType = $value['type']; $path = explode('/', $fName); $filename = $path[count($path) - 1]; // rename this file to go into the secure directory if (!rename($fName, $config->customFileUploadDir . $filename)) { CRM_Core_Error::statusBounce(ts('Could not move custom file to custom upload directory')); break; } if ($customValueId) { $query = "\nSELECT {$columnName}\n FROM {$tableName}\n WHERE id = %1"; $params = array(1 => array($customValueId, 'Integer')); $fileId = CRM_Core_DAO::singleValueQuery($query, $params); } $fileDAO =& new CRM_Core_DAO_File(); if ($fileId) { $fileDAO->id = $fileId; } $fileDAO->uri = $filename; $fileDAO->mime_type = $mimeType; $fileDAO->upload_date = date('Ymdhis'); $fileDAO->save(); $fileId = $fileDAO->id; $value = $filename; } if (!is_array($customFormatted)) { $customFormatted = array(); } if (!array_key_exists($customFieldId, $customFormatted)) { $customFormatted[$customFieldId] = array(); } $index = -1; if ($customValueId) { $index = $customValueId; } if (!array_key_exists($index, $customFormatted[$customFieldId])) { $customFormatted[$customFieldId][$index] = array(); } $customFormatted[$customFieldId][$index] = array('id' => $customValueId > 0 ? $customValueId : null, 'value' => $value, 'type' => $customFields[$customFieldId]['data_type'], 'custom_field_id' => $customFieldId, 'custom_group_id' => $groupID, 'table_name' => $tableName, 'column_name' => $columnName, 'file_id' => $fileId, 'is_multiple' => $customFields[$customFieldId]['is_multiple']); //we need to sort so that custom fields are created in the order of entry krsort($customFormatted[$customFieldId]); return $customFormatted; }
/** * Build the form * * @access public * * @return void */ function buildQuickForm() { $this->set('context', 'advanced'); $this->_searchPane = CRM_Utils_Array::value('searchPane', $_GET); $this->_searchOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'advanced_search_options'); if (!$this->_searchPane || $this->_searchPane == 'basic') { CRM_Contact_Form_Search_Criteria::basic($this); } $allPanes = array(); $paneNames = array(ts('Address Fields') => 'location', ts('Custom Fields') => 'custom', ts('Activities') => 'activity', ts('Relationships') => 'relationship', ts('Demographics') => 'demographics', ts('Notes') => 'notes', ts('Change Log') => 'changeLog'); //check if there are any custom data searchable fields $groupDetails = array(); $extends = array_merge(array('Contact', 'Individual', 'Household', 'Organization'), CRM_Contact_BAO_ContactType::subTypes()); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); // if no searchable fields unset panel if (empty($groupDetails)) { unset($paneNames[ts('Custom Fields')]); } foreach ($paneNames as $name => $type) { if (!$this->_searchOptions[$type]) { unset($paneNames[$name]); } } $components = CRM_Core_Component::getEnabledComponents(); $componentPanes = array(); foreach ($components as $name => $component) { if (in_array($name, array_keys($this->_searchOptions)) && $this->_searchOptions[$name] && CRM_Core_Permission::access($component->name)) { $componentPanes[$name] = $component->registerAdvancedSearchPane(); $componentPanes[$name]['name'] = $name; } } usort($componentPanes, array('CRM_Utils_Sort', 'cmpFunc')); foreach ($componentPanes as $name => $pane) { // FIXME: we should change the use of $name here to keyword $paneNames[$pane['title']] = $pane['name']; } $hookPanes = array(); CRM_Contact_BAO_Query_Hook::singleton()->registerAdvancedSearchPane($hookPanes); $paneNames = array_merge($paneNames, $hookPanes); $this->_paneTemplatePath = array(); foreach ($paneNames as $name => $type) { if (!array_key_exists($type, $this->_searchOptions) && !in_array($type, $hookPanes)) { continue; } $allPanes[$name] = array('url' => CRM_Utils_System::url('civicrm/contact/search/advanced', "snippet=1&searchPane={$type}&qfKey={$this->controller->_key}"), 'open' => 'false', 'id' => $type); // see if we need to include this paneName in the current form if ($this->_searchPane == $type || CRM_Utils_Array::value("hidden_{$type}", $_POST) || CRM_Utils_Array::value("hidden_{$type}", $this->_formValues)) { $allPanes[$name]['open'] = 'true'; if (CRM_Utils_Array::value($type, $components)) { $c = $components[$type]; $this->add('hidden', "hidden_{$type}", 1); $c->buildAdvancedSearchPaneForm($this); $this->_paneTemplatePath[$type] = $c->getAdvancedSearchPaneTemplatePath(); } else { if (in_array($type, $hookPanes)) { CRM_Contact_BAO_Query_Hook::singleton()->buildAdvancedSearchPaneForm($this, $type); CRM_Contact_BAO_Query_Hook::singleton()->setAdvancedSearchPaneTemplatePath($this->_paneTemplatePath, $type); } else { CRM_Contact_Form_Search_Criteria::$type($this); $template = ucfirst($type); $this->_paneTemplatePath[$type] = "CRM/Contact/Form/Search/Criteria/{$template}.tpl"; } } } } $this->assign('allPanes', $allPanes); if (!$this->_searchPane) { parent::buildQuickForm(); } else { $this->assign('suppressForm', TRUE); } }
/** * Check if we are rendering mixed profiles. * * @param array $profileIds * Associated array of profile ids. * * @return bool * true if profile is mixed */ public static function checkForMixProfiles($profileIds) { $mixProfile = FALSE; $contactTypes = array('Individual', 'Household', 'Organization'); $subTypes = CRM_Contact_BAO_ContactType::subTypes(); $components = array('Contribution', 'Participant', 'Membership', 'Activity'); $typeCount = array('ctype' => array(), 'subtype' => array()); foreach ($profileIds as $gid) { $profileType = CRM_Core_BAO_UFField::getProfileType($gid); // ignore profile of type Contact if ($profileType == 'Contact') { continue; } if (in_array($profileType, $contactTypes)) { if (!isset($typeCount['ctype'][$profileType])) { $typeCount['ctype'][$profileType] = 1; } // check if we are rendering profile of different contact types if (count($typeCount['ctype']) == 2) { $mixProfile = TRUE; break; } } elseif (in_array($profileType, $components)) { $mixProfile = TRUE; break; } else { if (!isset($typeCount['subtype'][$profileType])) { $typeCount['subtype'][$profileType] = 1; } // check if we are rendering profile of different contact sub types if (count($typeCount['subtype']) == 2) { $mixProfile = TRUE; break; } } } return $mixProfile; }
/** * Generate the custom Data Fields based * on the is_searchable * * @access private * @return void */ static function custom(&$form) { $form->add('hidden', 'hidden_custom', 1); $extends = array_merge(array('Contact', 'Individual', 'Household', 'Organization'), CRM_Contact_BAO_ContactType::subTypes()); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(null, true, $extends); $form->assign('groupTree', $groupDetails); foreach ($groupDetails as $key => $group) { $_groupTitle[$key] = $group['name']; CRM_Core_ShowHideBlocks::links($form, $group['name'], '', ''); $groupId = $group['id']; foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, false, false, true); } } }
/** * Build the form object. * * @return void */ public function buildQuickForm() { $this->assignToTemplate(); $productID = $this->get('productID'); $option = $this->get('option'); $membershipTypeID = $this->get('membershipTypeID'); $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values)); if ($productID) { CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option); } if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) { $this->assign('lineItem', $this->_lineItem); } else { if (is_array($membershipTypeID)) { $membershipTypeID = current($membershipTypeID); } $this->assign('is_quick_config', 1); $this->_params['is_quick_config'] = 1; } $this->assign('priceSetID', $this->_priceSetId); $this->assign('useForMember', $this->get('useForMember')); $params = $this->_params; $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings'); $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings); if ($invoicing) { $getTaxDetails = FALSE; $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings); foreach ($this->_lineItem as $key => $value) { foreach ($value as $v) { if (isset($v['tax_rate'])) { if ($v['tax_rate'] != '') { $getTaxDetails = TRUE; } } } } $this->assign('getTaxDetails', $getTaxDetails); $this->assign('taxTerm', $taxTerm); $this->assign('totalTaxAmount', $params['tax_amount']); } if ($this->_honor_block_is_active && !empty($params['soft_credit_type_id'])) { $honorName = NULL; $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); $this->assign('honor_block_is_active', $this->_honor_block_is_active); $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]); CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor'], $params['honoree_profile_id']); $fieldTypes = array('Contact'); $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']); $this->buildCustom($params['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes); } $qParams = "reset=1&id={$this->_id}"; //pcp elements if ($this->_pcpId) { $qParams .= "&pcpId={$this->_pcpId}"; $this->assign('pcpBlock', TRUE); foreach (array('pcp_display_in_roll', 'pcp_is_anonymous', 'pcp_roll_nickname', 'pcp_personal_note') as $val) { if (!empty($this->_params[$val])) { $this->assign($val, $this->_params[$val]); } } } $this->assign('qParams', $qParams); if ($membershipTypeID) { $transactionID = $this->get('membership_trx_id'); $membershipAmount = $this->get('membership_amount'); $renewalMode = $this->get('renewal_mode'); $this->assign('membership_trx_id', $transactionID); $this->assign('membership_amount', $membershipAmount); $this->assign('renewal_mode', $renewalMode); $this->buildMembershipBlock($this->_membershipContactID, FALSE, $membershipTypeID, TRUE, NULL); if (!empty($params['auto_renew'])) { $this->assign('auto_renew', TRUE); } } $this->_separateMembershipPayment = $this->get('separateMembershipPayment'); $this->assign("is_separate_payment", $this->_separateMembershipPayment); $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE); $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE); if (!empty($params['hidden_onbehalf_profile'])) { $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id); $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); $profileId = $OnBehalfProfile[0]; $fieldTypes = array('Contact', 'Organization'); $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization'); $fieldTypes = array_merge($fieldTypes, $contactSubType); if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) { $fieldTypes = array_merge($fieldTypes, array('Membership')); } else { $fieldTypes = array_merge($fieldTypes, array('Contribution')); } $this->buildCustom($profileId, 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes); } $this->assign('trxn_id', CRM_Utils_Array::value('trxn_id', $this->_params)); $this->assign('receive_date', CRM_Utils_Date::mysqlToIso(CRM_Utils_Array::value('receive_date', $this->_params))); $defaults = array(); $fields = array(); foreach ($this->_fields as $name => $dontCare) { if ($name != 'onbehalf' || $name != 'honor') { $fields[$name] = 1; } } $fields['state_province'] = $fields['country'] = $fields['email'] = 1; $contact = $this->_params = $this->controller->exportValues('Main'); foreach ($fields as $name => $dontCare) { if (isset($contact[$name])) { $defaults[$name] = $contact[$name]; if (substr($name, 0, 7) == 'custom_') { $timeField = "{$name}_time"; if (isset($contact[$timeField])) { $defaults[$timeField] = $contact[$timeField]; } } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && !empty($contact[$name . '_custom'])) { $defaults[$name . '_custom'] = $contact[$name . '_custom']; } } } $this->_submitValues = array_merge($this->_submitValues, $defaults); $this->setDefaults($defaults); $values['entity_id'] = $this->_id; $values['entity_table'] = 'civicrm_contribution_page'; CRM_Friend_BAO_Friend::retrieve($values, $data); $tellAFriend = FALSE; if ($this->_pcpId) { if ($this->_pcpBlock['is_tellfriend_enabled']) { $this->assign('friendText', ts('Tell a Friend')); $subUrl = "eid={$this->_pcpId}&blockId={$this->_pcpBlock['id']}&pcomponent=pcp"; $tellAFriend = TRUE; } } elseif (!empty($data['is_active'])) { $friendText = $data['title']; $this->assign('friendText', $friendText); $subUrl = "eid={$this->_id}&pcomponent=contribute"; $tellAFriend = TRUE; } if ($tellAFriend) { if ($this->_action & CRM_Core_Action::PREVIEW) { $url = CRM_Utils_System::url("civicrm/friend", "reset=1&action=preview&{$subUrl}"); } else { $url = CRM_Utils_System::url("civicrm/friend", "reset=1&{$subUrl}"); } $this->assign('friendURL', $url); } $this->freeze(); // can we blow away the session now to prevent hackery // CRM-9491 $this->controller->reset(); }
/** * Global validation rules for the form. * * @param array $fields * Posted values of the form. * * @param $files * @param $self * * @return array * list of errors to be posted back to the form */ public static function formRule($fields, $files, $self) { $is_required = CRM_Utils_Array::value('is_required', $fields, FALSE); $is_registration = CRM_Utils_Array::value('is_registration', $fields, FALSE); $is_view = CRM_Utils_Array::value('is_view', $fields, FALSE); $in_selector = CRM_Utils_Array::value('in_selector', $fields, FALSE); $is_active = CRM_Utils_Array::value('is_active', $fields, FALSE); $errors = array(); if ($is_view && $is_registration) { $errors['is_registration'] = ts('View Only cannot be selected if this field is to be included on the registration form'); } if ($is_view && $is_required) { $errors['is_view'] = ts('A View Only field cannot be required'); } $entityName = $fields['field_name'][0]; if (!$entityName) { $errors['field_name'] = ts('Please select a field name'); } if ($in_selector && in_array($entityName, array('Contribution', 'Participant', 'Membership', 'Activity'))) { $errors['in_selector'] = ts("'In Selector' cannot be checked for %1 fields.", array(1 => $entityName)); } $isCustomField = FALSE; $profileFieldName = CRM_Utils_Array::value(1, $fields['field_name']); if ($profileFieldName) { //get custom field id $customFieldId = explode('_', $profileFieldName); if ($customFieldId[0] == 'custom') { $customField = new CRM_Core_DAO_CustomField(); $customField->id = $customFieldId[1]; $customField->find(TRUE); $isCustomField = TRUE; if (!empty($fields['field_id']) && !$customField->is_active && $is_active) { $errors['field_name'] = ts('Cannot set this field "Active" since the selected custom field is disabled.'); } //check if profile already has a different multi-record custom set field configured $customGroupId = CRM_Core_BAO_CustomField::isMultiRecordField($profileFieldName); if ($customGroupId) { if ($profileMultiRecordCustomGid = CRM_Core_BAO_UFField::checkMultiRecordFieldExists($self->_gid)) { if ($customGroupId != $profileMultiRecordCustomGid) { $errors['field_name'] = ts("You cannot configure multi-record custom fields belonging to different custom sets in one profile"); } } } } } // Get list of fields already in the group $groupFields = CRM_Core_BAO_UFGroup::getFields($fields['group_id'], FALSE, NULL, NULL, NULL, TRUE, NULL, TRUE); // Check if we already added a primary field of the same communication type self::formRulePrimaryCheck($fields, $profileFieldName, $groupFields, $errors); //check profile is configured for double option process //adding group field, email field should be present in the group //fixed for issue CRM-2861 & CRM-4153 if (CRM_Core_BAO_UFGroup::isProfileDoubleOptin()) { if (CRM_Utils_Array::value(1, $fields['field_name']) == 'group') { $dao = new CRM_Core_BAO_UFField(); $dao->uf_group_id = $fields['group_id']; $dao->find(); $emailField = FALSE; while ($dao->fetch()) { //check email field is present in the group if ($dao->field_name == 'email') { $emailField = TRUE; break; } } if (!$emailField) { $disableSettingURL = CRM_Utils_System::url('civicrm/admin/setting/preferences/mailing', 'reset=1'); $errors['field_name'] = ts('Your site is currently configured to require double-opt in when users join (subscribe) to Group(s) via a Profile form. In this mode, you need to include an Email field in a Profile BEFORE you can add the Group(s) field. This ensures that an opt-in confirmation email can be sent. Your site administrator can disable double opt-in on the civimail admin settings: <em>%1</em>', array(1 => $disableSettingURL)); } } } //fix for CRM-3037 $fieldType = $fields['field_name'][0]; //get the group type. $groupType = CRM_Core_BAO_UFGroup::calculateGroupType($self->_gid, FALSE, CRM_Utils_Array::value('field_id', $fields)); switch ($fieldType) { case 'Contact': self::formRuleSubType($fieldType, $groupType, $errors); break; case 'Individual': if (in_array('Activity', $groupType) || in_array('Household', $groupType) || in_array('Organization', $groupType)) { //CRM-7603 - need to support activity + individual. //$errors['field_name'] = //ts( 'Cannot add or update profile field type Individual with combination of Household or Organization or Activity' ); if (in_array('Household', $groupType) || in_array('Organization', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Individual with combination of Household or Organization'); } } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Household': if (in_array('Activity', $groupType) || in_array('Individual', $groupType) || in_array('Organization', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Household with combination of Individual or Organization or Activity'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Organization': if (in_array('Activity', $groupType) || in_array('Household', $groupType) || in_array('Individual', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Organization with combination of Household or Individual or Activity'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Activity': if (in_array('Individual', $groupType) || in_array('Membership', $groupType) || in_array('Contribution', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType) || in_array('Participant', $groupType)) { //CRM-7603 - need to support activity + contact type. //$errors['field_name'] = //ts( 'Cannot add or update profile field type Activity with combination Participant or Membership or Contribution or Household or Organization or Individual' ); if (in_array('Membership', $groupType) || in_array('Contribution', $groupType) || in_array('Participant', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Activity with combination Participant or Membership or Contribution'); } } else { self::formRuleSubType($fieldType, $groupType, $errors); } if ($isCustomField && !isset($errors['field_name'])) { self::formRuleCustomDataExtentColumnValue($customField, $self->_gid, $fieldType, $errors); } break; case 'Participant': if (in_array('Membership', $groupType) || in_array('Contribution', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType) || in_array('Activity', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Participant with combination of Activity or Membership or Contribution or Household or Organization.'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Contribution': //special case where in we allow contribution + oganization fields, for on behalf feature $profileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'on_behalf_organization', 'id', 'name'); if (in_array('Participant', $groupType) || in_array('Membership', $groupType) || $profileId != $self->_gid && in_array('Organization', $groupType) || in_array('Household', $groupType) || in_array('Activity', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Contribution with combination of Activity or Membership or Participant or Household or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Membership': //special case where in we allow contribution + oganization fields, for on behalf feature $profileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'on_behalf_organization', 'id', 'name'); if (in_array('Participant', $groupType) || in_array('Contribution', $groupType) || $profileId != $self->_gid && in_array('Organization', $groupType) || in_array('Household', $groupType) || in_array('Activity', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Membership with combination of Activity or Participant or Contribution or Household or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; default: $profileType = CRM_Core_BAO_UFField::getProfileType($fields['group_id'], TRUE, FALSE, TRUE); if (CRM_Contact_BAO_ContactType::isaSubType($fieldType)) { if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { if ($fieldType != $profileType) { $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(1 => $fieldType, 2 => $profileType)); } } else { $basicType = CRM_Contact_BAO_ContactType::getBasicType($fieldType); if ($profileType && $profileType != $basicType && $profileType != 'Contact') { $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(1 => $fieldType, 2 => $profileType)); } } } elseif (CRM_Utils_Array::value(1, $fields['field_name']) == 'contact_sub_type' && !in_array($profileType, array('Individual', 'Household', 'Organization')) && !in_array($profileType, CRM_Contact_BAO_ContactType::subTypes())) { $errors['field_name'] = ts('Cannot add or update profile field Contact Subtype as profile type is not one of Individual, Household or Organization.'); } } return empty($errors) ? TRUE : $errors; }
/** * Profile.GetAngularSettings API * * @param array $params * @return array API result descriptor * @see civicrm_api3_create_success * @see civicrm_api3_create_error * @throws API_Exception */ function civicrm_api3_profile_getangularsettings($params) { $returnValues = array('PseudoConstant' => array('locationType' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'), 'websiteType' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'), 'phoneType' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id')), 'initialProfileList' => civicrm_api('UFGroup', 'get', array('version' => 3, 'sequential' => 1, 'is_active' => 1, 'rowCount' => 1000)), 'contactSubTypes' => CRM_Contact_BAO_ContactType::subTypes(), 'profilePreviewKey' => CRM_Core_Key::get('CRM_UF_Form_Inline_Preview', TRUE)); return civicrm_api3_create_success($returnValues, $params, 'Profile', 'getangularsettings'); }
/** * Build form for related contacts / on behalf of organization. * * @param CRM_Core_Form $form * */ public static function buildQuickForm(&$form) { $form->assign('fieldSetTitle', ts('Organization Details')); $form->assign('buildOnBehalfForm', TRUE); $contactID = $form->_contactID; if ($contactID && count($form->_employers) >= 1) { $form->add('text', 'organization_id', ts('Select an existing related Organization OR enter a new one')); $form->add('select', 'onbehalfof_id', '', CRM_Utils_Array::collect('name', $form->_employers)); $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->add('checkbox', 'mode', ''); } $profileFields = CRM_Core_BAO_UFGroup::getFields($form->_profileId, FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL); $fieldTypes = array('Contact', 'Organization'); $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization'); $fieldTypes = array_merge($fieldTypes, $contactSubType); if (is_array($form->_membershipBlock) && !empty($form->_membershipBlock)) { $fieldTypes = array_merge($fieldTypes, array('Membership')); } else { $fieldTypes = array_merge($fieldTypes, array('Contribution')); } 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; } CRM_Core_BAO_UFGroup::buildProfile($form, $field, NULL, NULL, FALSE, 'onbehalf'); } } $form->assign('onBehalfOfFields', $profileFields); $form->addElement('hidden', 'hidden_onbehalf_profile', 1); }
/** * FIXME: Move to somewhere more useful * FIXME: Do real mapping of "types" * * @param string $extends * Entity type; note: "Individual" means "Individual|Contact"; "Household" means "Household|Contact". * @param string $title * A string to use in section headers. * @param array $availableFields * List of fields that are allowed in profiles, e.g. $availableFields['my_field']['field_type']. * @return array * with keys 'sections' and 'schema' * @see js/model/crm.core.js * @see js/model/crm.mappedcore.js */ public static function convertCiviModelToBackboneModel($extends, $title, $availableFields) { $locationFields = CRM_Core_BAO_UFGroup::getLocationFields(); $result = array('schema' => array(), 'sections' => array()); // build field list foreach ($availableFields as $fieldName => $field) { switch ($extends) { case 'Individual': case 'Organization': case 'Household': if ($field['field_type'] != $extends && $field['field_type'] != 'Contact' && !in_array($field['field_type'], CRM_Contact_BAO_ContactType::subTypes($extends))) { continue 2; } break; default: if ($field['field_type'] != $extends) { continue 2; } } $result['schema'][$fieldName] = array('type' => 'Text', 'title' => $field['title'], 'civiFieldType' => $field['field_type']); if (in_array($fieldName, $locationFields)) { $result['schema'][$fieldName]['civiIsLocation'] = TRUE; } if ($fieldName == 'url') { $result['schema'][$fieldName]['civiIsWebsite'] = TRUE; } if (in_array($fieldName, array('phone', 'phone_and_ext'))) { // FIXME what about phone_ext? $result['schema'][$fieldName]['civiIsPhone'] = TRUE; } } // build section list $result['sections']['default'] = array('title' => $title, 'is_addable' => FALSE); $customGroup = CRM_Core_BAO_CustomGroup::getAllCustomGroupsByBaseEntity($extends); $customGroup->orderBy('weight'); $customGroup->is_active = 1; $customGroup->find(); while ($customGroup->fetch()) { $sectionName = 'cg_' . $customGroup->id; $section = array('title' => ts('%1: %2', array(1 => $title, 2 => $customGroup->title)), 'is_addable' => $customGroup->is_reserved ? FALSE : TRUE, 'custom_group_id' => $customGroup->id, 'extends_entity_column_id' => $customGroup->extends_entity_column_id, 'extends_entity_column_value' => CRM_Utils_Array::explodePadded($customGroup->extends_entity_column_value), 'is_reserved' => $customGroup->is_reserved ? TRUE : FALSE); $result['sections'][$sectionName] = $section; } // put fields in their sections $fields = CRM_Core_BAO_CustomField::getFields($extends); foreach ($fields as $fieldId => $field) { $sectionName = 'cg_' . $field['custom_group_id']; $fieldName = 'custom_' . $fieldId; if (isset($result['schema'][$fieldName])) { $result['schema'][$fieldName]['section'] = $sectionName; $result['schema'][$fieldName]['civiIsMultiple'] = (bool) CRM_Core_BAO_CustomField::isMultiRecordField($fieldId); } } return $result; }
/** * Global validation rules for the form. * * @param array $values * @param $files * @param CRM_Core_Form $form * * @return array * list of errors to be posted back to the form */ public static function formRule($values, $files, $form) { if (!empty($values['is_online_registration'])) { if (!$values['confirm_title']) { $errorMsg['confirm_title'] = ts('Please enter a Title for the registration Confirmation Page'); } if (!$values['thankyou_title']) { $errorMsg['thankyou_title'] = ts('Please enter a Title for the registration Thank-you Page'); } if ($values['is_email_confirm']) { if (!$values['confirm_from_name']) { $errorMsg['confirm_from_name'] = ts('Please enter Confirmation Email FROM Name.'); } if (!$values['confirm_from_email']) { $errorMsg['confirm_from_email'] = ts('Please enter Confirmation Email FROM Email Address.'); } } if (isset($values['registration_start_date']) && isset($values['registration_end_date'])) { $start = CRM_Utils_Date::processDate($values['registration_start_date']); $end = CRM_Utils_Date::processDate($values['registration_end_date']); if ($end < $start) { $errorMsg['registration_end_date'] = ts('Registration end date should be after Registration start date'); } } //check that the selected profiles have either firstname+lastname or email required $profileIds = array(CRM_Utils_Array::value('custom_pre_id', $values), CRM_Utils_Array::value('custom_post_id', $values)); $additionalProfileIds = array(CRM_Utils_Array::value('additional_custom_pre_id', $values), CRM_Utils_Array::value('additional_custom_post_id', $values)); //additional profile fields default to main if not set if (!is_numeric($additionalProfileIds[0])) { $additionalProfileIds[0] = $profileIds[0]; } if (!is_numeric($additionalProfileIds[1])) { $additionalProfileIds[1] = $profileIds[1]; } //add multiple profiles if set self::addMultipleProfiles($profileIds, $values, 'custom_post_id_multiple'); self::addMultipleProfiles($additionalProfileIds, $values, 'additional_custom_post_id_multiple'); $isProfileComplete = self::isProfileComplete($profileIds); $isAdditionalProfileComplete = self::isProfileComplete($additionalProfileIds); //Check main profiles have an email address available if 'send confirmation email' is selected if ($values['is_email_confirm']) { $emailFields = self::getEmailFields($profileIds); if (!count($emailFields)) { $errorMsg['is_email_confirm'] = ts("Please add a profile with an email address if 'Send Confirmation Email?' is selected"); } } $additionalCustomPreId = $additionalCustomPostId = NULL; $isPreError = $isPostError = TRUE; if (!empty($values['allow_same_participant_emails']) && !empty($values['is_multiple_registrations'])) { $types = array_merge(array('Individual'), CRM_Contact_BAO_ContactType::subTypes('Individual')); $profiles = CRM_Core_BAO_UFGroup::getProfiles($types); //check for additional custom pre profile $additionalCustomPreId = CRM_Utils_Array::value('additional_custom_pre_id', $values); if (!empty($additionalCustomPreId)) { if (!($additionalCustomPreId == 'none')) { $customPreId = $additionalCustomPreId; } else { $isPreError = FALSE; } } else { $customPreId = !empty($values['custom_pre_id']) ? $values['custom_pre_id'] : NULL; } //check whether the additional custom pre profile is of type 'Individual' and its subtypes if (!empty($customPreId)) { $profileTypes = CRM_Core_BAO_UFGroup::profileGroups($customPreId); foreach ($types as $individualTypes) { if (in_array($individualTypes, $profileTypes)) { $isPreError = FALSE; break; } } } else { $isPreError = FALSE; } // We don't have required Individual fields in the pre-custom profile, so now check the post-custom profile if ($isPreError) { $additionalCustomPostId = CRM_Utils_Array::value('additional_custom_post_id', $values); if (!empty($additionalCustomPostId)) { if (!($additionalCustomPostId == 'none')) { $customPostId = $additionalCustomPostId; } else { $isPostError = FALSE; } } else { $customPostId = !empty($values['custom_post_id']) ? $values['custom_post_id'] : NULL; } //check whether the additional custom post profile is of type 'Individual' and its subtypes if (!empty($customPostId)) { $profileTypes = CRM_Core_BAO_UFGroup::profileGroups($customPostId); foreach ($types as $individualTypes) { if (in_array($individualTypes, $profileTypes)) { $isPostError = FALSE; break; } } } else { $isPostError = FALSE; } if (empty($customPreId) && empty($customPostId)) { $errorMsg['additional_custom_pre_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'"); } if ($isPostError) { $errorMsg['additional_custom_post_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'"); } } } if (!$isProfileComplete) { $errorMsg['custom_pre_id'] = ts("Please include a Profile for online registration that contains an Email Address field and / or First Name + Last Name fields."); } if (!$isAdditionalProfileComplete) { $errorMsg['additional_custom_pre_id'] = ts("Please include a Profile for online registration of additional participants that contains an Email Address field and / or First Name + Last Name fields."); } // // CRM-8485 // $config = CRM_Core_Config::singleton(); // if ( $config->doNotAttachPDFReceipt ) { // if (!empty($values['custom_post_id_multiple'])) { // foreach( $values['custom_post_id_multiple'] as $count => $customPostMultiple ) { // if ( $customPostMultiple ) { // $errorMsg["custom_post_id_multiple[{$count}]"] = ts('Please disable PDF receipt as an attachment in <a href="%1">Miscellaneous Settings</a> if you want to add additional profiles.', array( 1 => CRM_Utils_System::url( 'civicrm/admin/setting/misc', 'reset=1' ) ) ); // break; // } // } // } // // if (!empty($values['is_multiple_registrations']) && // CRM_Utils_Array::value('additional_custom_post_id_multiple', $values) ) { // foreach( $values['additional_custom_post_id_multiple'] as $count => $customPostMultiple ) { // if ( $customPostMultiple ) { // $errorMsg["additional_custom_post_id_multiple[{$count}]"] = ts('Please disable PDF receipt as an attachment in <a href="%1">Miscellaneous Settings</a> if you want to add additional profiles.', array( 1 => CRM_Utils_System::url( 'civicrm/admin/setting/misc', 'reset=1' ) ) ); // break; // } // } // } // } if (!empty($errorMsg)) { if (!empty($values['custom_post_id_multiple'])) { foreach ($values['custom_post_id_multiple'] as $count => $customPostMultiple) { self::buildMultipleProfileBottom($form, $count); } $form->assign('profilePostMultiple', $values['custom_post_id_multiple']); } if (!empty($values['additional_custom_post_id_multiple'])) { foreach ($values['additional_custom_post_id_multiple'] as $count => $customPostMultiple) { self::buildMultipleProfileBottom($form, $count, 'additional_', ts('Profile for Additional Participants')); } $form->assign('profilePostMultipleAdd', $values['additional_custom_post_id_multiple']); } } } if (!empty($errorMsg)) { return $errorMsg; } return TRUE; }
/** * Generate the custom Data Fields based * on the is_searchable * * * @param $form * * @return void */ public static function custom(&$form) { $form->add('hidden', 'hidden_custom', 1); $extends = array_merge(array('Contact', 'Individual', 'Household', 'Organization'), CRM_Contact_BAO_ContactType::subTypes()); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); $form->assign('groupTree', $groupDetails); foreach ($groupDetails as $key => $group) { $_groupTitle[$key] = $group['name']; CRM_Core_ShowHideBlocks::links($form, $group['name'], '', ''); $groupId = $group['id']; foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; if ($field['data_type'] == 'Date' && $field['is_search_range']) { CRM_Core_Form_Date::buildDateRange($form, $elementName, 1, '_from', '_to', ts('From:'), FALSE); } else { CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } //TODO: validate for only one state if prox_distance isset }
/** * Get the profile type (eg: individual/organization/household) * * @param string $ufGroupType * @param bool $returnMixType * This is true, then field type of mix profile field is returned. * @param bool $onlyPure * True if only pure profiles are required. * @param bool $skipComponentType * * @return string profile group_type * */ public static function calculateProfileType($ufGroupType, $returnMixType = TRUE, $onlyPure = FALSE, $skipComponentType = FALSE) { // profile types $contactTypes = array('Contact', 'Individual', 'Household', 'Organization'); $subTypes = CRM_Contact_BAO_ContactType::subTypes(); $components = array('Contribution', 'Participant', 'Membership', 'Activity'); $profileTypes = array(); if ($ufGroupType) { $typeParts = explode(CRM_Core_DAO::VALUE_SEPARATOR, $ufGroupType); $profileTypes = explode(',', $typeParts[0]); } if ($onlyPure) { if (count($profileTypes) == 1) { return $profileTypes[0]; } else { return NULL; } } //we need to unset Contact if (count($profileTypes) > 1) { $index = array_search('Contact', $profileTypes); if ($index !== FALSE) { unset($profileTypes[$index]); } } $profileType = $mixProfileType = NULL; // this case handles pure profile if (count($profileTypes) == 1) { $profileType = array_pop($profileTypes); } else { //check the there are any components include in profile $componentCount = array(); foreach ($components as $value) { if (in_array($value, $profileTypes)) { $componentCount[] = $value; } } //check contact type included in profile $contactTypeCount = array(); foreach ($contactTypes as $value) { if (in_array($value, $profileTypes)) { $contactTypeCount[] = $value; } } // subtype counter $subTypeCount = array(); foreach ($subTypes as $value) { if (in_array($value, $profileTypes)) { $subTypeCount[] = $value; } } if (!$skipComponentType && count($componentCount) == 1) { $profileType = $componentCount[0]; } elseif (count($componentCount) > 1) { $mixProfileType = $componentCount[1]; } elseif (count($subTypeCount) == 1) { $profileType = $subTypeCount[0]; } elseif (count($contactTypeCount) == 1) { $profileType = $contactTypeCount[0]; } elseif (count($subTypeCount) > 1) { // this is mix subtype profiles $mixProfileType = $subTypeCount[1]; } elseif (count($contactTypeCount) > 1) { // this is mix contact profiles $mixProfileType = $contactTypeCount[1]; } } if ($mixProfileType) { if ($returnMixType) { return $mixProfileType; } else { return 'Mixed'; } } else { return $profileType; } }
/** * global validation rules for the form * * @param array $fields posted values of the form * * @return array list of errors to be posted back to the form * @static * @access public */ static function formRule($values) { if (CRM_Utils_Array::value('is_online_registration', $values)) { if (!$values['confirm_title']) { $errorMsg['confirm_title'] = ts('Please enter a Title for the registration Confirmation Page'); } if (!$values['thankyou_title']) { $errorMsg['thankyou_title'] = ts('Please enter a Title for the registration Thank-you Page'); } if ($values['is_email_confirm']) { if (!$values['confirm_from_name']) { $errorMsg['confirm_from_name'] = ts('Please enter Confirmation Email FROM Name.'); } if (!$values['confirm_from_email']) { $errorMsg['confirm_from_email'] = ts('Please enter Confirmation Email FROM Email Address.'); } } $additionalCustomPreId = $additionalCustomPostId = null; $isPreError = $isPostError = true; if (CRM_Utils_Array::value('allow_same_participant_emails', $values) && CRM_Utils_Array::value('is_multiple_registrations', $values)) { $types = array_merge(array('Individual'), CRM_Contact_BAO_ContactType::subTypes('Individual')); $profiles = CRM_Core_BAO_UFGroup::getProfiles($types); //check for additional custom pre profile $additionalCustomPreId = CRM_Utils_Array::value('additional_custom_pre_id', $values); if (!empty($additionalCustomPreId)) { if (!($additionalCustomPreId == 'none')) { $customPreId = $additionalCustomPreId; } else { $isPreError = false; } } else { $customPreId = CRM_Utils_Array::value('custom_pre_id', $values) ? $values['custom_pre_id'] : null; } //check whether the additional custom pre profile is of type 'Individual' and its subtypes if (!empty($customPreId)) { $profileTypes = CRM_Core_BAO_UFGroup::profileGroups($customPreId); foreach ($types as $individualTypes) { if (in_array($individualTypes, $profileTypes)) { $isPreError = false; break; } } } else { $isPreError = false; } //check for additional custom post profile $additionalCustomPostId = CRM_Utils_Array::value('additional_custom_post_id', $values); if (!empty($additionalCustomPostId)) { if (!($additionalCustomPostId == 'none')) { $customPostId = $additionalCustomPostId; } else { $isPostError = false; } } else { $customPostId = CRM_Utils_Array::value('custom_post_id', $values) ? $values['custom_post_id'] : null; } //check whether the additional custom post profile is of type 'Individual' and its subtypes if (!empty($customPostId)) { $profileTypes = CRM_Core_BAO_UFGroup::profileGroups($customPostId); foreach ($types as $individualTypes) { if (in_array($individualTypes, $profileTypes)) { $isPostError = false; break; } } } else { $isPostError = false; } if ($isPreError || empty($customPreId) && empty($customPostId)) { $errorMsg['additional_custom_pre_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'"); } if ($isPostError) { $errorMsg['additional_custom_post_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'"); } } } if (!empty($errorMsg)) { return $errorMsg; } return true; }
static function buildSubTypes() { $parent = CRM_Utils_Array::value('parentId', $_POST); switch ($parent) { case 1: $contactType = 'Individual'; break; case 2: $contactType = 'Household'; break; case 4: $contactType = 'Organization'; break; } require_once 'CRM/Contact/BAO/ContactType.php'; $subTypes = CRM_Contact_BAO_ContactType::subTypes($contactType); sort($subTypes); echo json_encode($subTypes); exit; }
/** * Function to actually build the form * * @return void * @access public */ public function buildQuickForm() { $this->assignToTemplate(); $params = $this->_params; $honor_block_is_active = $this->get('honor_block_is_active'); // make sure we have values for it if ($honor_block_is_active && !empty($params['soft_credit_type_id'])) { $honorName = null; $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); $this->assign('honor_block_is_active', $honor_block_is_active); $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]); CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor'], $params['honoree_profile_id']); $fieldTypes = array('Contact'); $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']); $this->buildCustom($params['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes); } $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values)); $amount_block_is_active = $this->get('amount_block_is_active'); $this->assign('amount_block_is_active', $amount_block_is_active); if (!empty($params['selectProduct']) && $params['selectProduct'] != 'no_thanks') { $option = CRM_Utils_Array::value('options_' . $params['selectProduct'], $params); $productID = $params['selectProduct']; CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option); $this->set('productID', $productID); $this->set('option', $option); } $config = CRM_Core_Config::singleton(); if (in_array('CiviMember', $config->enableComponents)) { if (isset($params['selectMembership']) && $params['selectMembership'] != 'no_thanks') { CRM_Member_BAO_Membership::buildMembershipBlock($this, $this->_id, $this->_membershipContactID, FALSE, $params['selectMembership'], FALSE); } else { $this->assign('membershipBlock', FALSE); } } $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE); $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE); if (!empty($params['hidden_onbehalf_profile'])) { $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id); $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); $profileId = $OnBehalfProfile[0]; $fieldTypes = array('Contact', 'Organization'); $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization'); $fieldTypes = array_merge($fieldTypes, $contactSubType); if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) { $fieldTypes = array_merge($fieldTypes, array('Membership')); } else { $fieldTypes = array_merge($fieldTypes, array('Contribution')); } $this->buildCustom($profileId, 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes); } $this->_separateMembershipPayment = $this->get('separateMembershipPayment'); $this->assign('is_separate_payment', $this->_separateMembershipPayment); if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) { $this->assign('lineItem', $this->_lineItem); } else { $this->assign('is_quick_config', 1); $this->_params['is_quick_config'] = 1; } $this->assign('priceSetID', $this->_priceSetId); $paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(false, null, 'name'); if ($this->_paymentProcessor && $this->_paymentProcessor['payment_processor_type_id'] == CRM_Utils_Array::key('Google_Checkout', $paymentProcessorType) && !$this->_params['is_pay_later'] && !($this->_amount == 0)) { $this->_checkoutButtonName = $this->getButtonName('next', 'checkout'); $this->add('image', $this->_checkoutButtonName, $this->_paymentProcessor['url_button'], array('class' => 'form-submit')); $this->addButtons(array(array('type' => 'back', 'name' => ts('<< Go Back')))); } else { if ($this->_contributeMode == 'notify' || !$this->_values['is_monetary'] || $this->_amount <= 0.0 || $this->_params['is_pay_later'] || $this->_separateMembershipPayment && $this->_amount <= 0.0) { $contribButton = ts('Continue >>'); $this->assign('button', ts('Continue')); } else { $contribButton = ts('Make Contribution'); $this->assign('button', ts('Make Contribution')); } $this->addButtons(array(array('type' => 'next', 'name' => $contribButton, 'spacing' => ' ', 'isDefault' => TRUE, 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');")), array('type' => 'back', 'name' => ts('Go Back')))); } $defaults = array(); $fields = array(); foreach ($this->_fields as $name => $dontCare) { if ($name != 'onbehalf' || $name != 'honor') { $fields[$name] = 1; } } $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1; $contact = $this->_params; foreach ($fields as $name => $dontCare) { if (isset($contact[$name])) { $defaults[$name] = $contact[$name]; if (substr($name, 0, 7) == 'custom_') { $timeField = "{$name}_time"; if (isset($contact[$timeField])) { $defaults[$timeField] = $contact[$timeField]; } if (isset($contact["{$name}_id"])) { $defaults["{$name}_id"] = $contact["{$name}_id"]; } } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && !empty($contact[$name . '_custom'])) { $defaults[$name . '_custom'] = $contact[$name . '_custom']; } } } $this->assign('useForMember', $this->get('useForMember')); // now fix all state country selectors CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults); $this->setDefaults($defaults); $this->freeze(); }
/** * Function to actually build the form * * @return void * @access public */ public function buildQuickForm() { $this->assignToTemplate(); $productID = $this->get('productID'); $option = $this->get('option'); $membershipTypeID = $this->get('membershipTypeID'); $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values)); if ($productID) { CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option); } if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $this->_priceSetId, 'is_quick_config')) { $this->assign('lineItem', $this->_lineItem); } else { if (is_array($membershipTypeID)) { $membershipTypeID = current($membershipTypeID); } $this->assign('is_quick_config', 1); $this->_params['is_quick_config'] = 1; } $this->assign('priceSetID', $this->_priceSetId); $this->assign('useForMember', $this->get('useForMember')); $params = $this->_params; $honor_block_is_active = $this->get('honor_block_is_active'); if ($honor_block_is_active && (!empty($params["honor_first_name"]) && !empty($params["honor_last_name"]) || !empty($params["honor_email"]))) { $this->assign('honor_block_is_active', $honor_block_is_active); $this->assign('honor_block_title', CRM_Utils_Array::value('honor_block_title', $this->_values)); $prefix = CRM_Core_PseudoConstant::individualPrefix(); $honor = CRM_Core_PseudoConstant::honor(); $this->assign('honor_type', $honor[$params["honor_type_id"]]); $this->assign('honor_prefix', $params["honor_prefix_id"] ? $prefix[$params["honor_prefix_id"]] : ' '); $this->assign('honor_first_name', $params["honor_first_name"]); $this->assign('honor_last_name', $params["honor_last_name"]); $this->assign('honor_email', $params["honor_email"]); } $qParams = "reset=1&id={$this->_id}"; //pcp elements if ($this->_pcpId) { $qParams .= "&pcpId={$this->_pcpId}"; $this->assign('pcpBlock', TRUE); foreach (array('pcp_display_in_roll', 'pcp_is_anonymous', 'pcp_roll_nickname', 'pcp_personal_note') as $val) { if (CRM_Utils_Array::value($val, $this->_params)) { $this->assign($val, $this->_params[$val]); } } } $this->assign('qParams', $qParams); if ($membershipTypeID) { $transactionID = $this->get('membership_trx_id'); $membershipAmount = $this->get('membership_amount'); $renewalMode = $this->get('renewal_mode'); $this->assign('membership_trx_id', $transactionID); $this->assign('membership_amount', $membershipAmount); $this->assign('renewal_mode', $renewalMode); CRM_Member_BAO_Membership::buildMembershipBlock($this, $this->_id, FALSE, $membershipTypeID, TRUE, NULL, $this->_membershipContactID); } $this->_separateMembershipPayment = $this->get('separateMembershipPayment'); $this->assign("is_separate_payment", $this->_separateMembershipPayment); $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE); $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE); if (CRM_Utils_Array::value('hidden_onbehalf_profile', $params)) { $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id); $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); $profileId = $OnBehalfProfile[0]; $fieldTypes = array('Contact', 'Organization'); $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization'); $fieldTypes = array_merge($fieldTypes, $contactSubType); if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) { $fieldTypes = array_merge($fieldTypes, array('Membership')); } else { $fieldTypes = array_merge($fieldTypes, array('Contribution')); } $this->buildCustom($profileId, 'onbehalfProfile', TRUE, TRUE, $fieldTypes); } $this->assign('trxn_id', CRM_Utils_Array::value('trxn_id', $this->_params)); $this->assign('receive_date', CRM_Utils_Date::mysqlToIso(CRM_Utils_Array::value('receive_date', $this->_params))); $defaults = array(); $options = array(); $fields = array(); $removeCustomFieldTypes = array('Contribution'); foreach ($this->_fields as $name => $dontCare) { if ($name == 'onbehalf') { foreach ($dontCare as $key => $value) { $fields['onbehalf'][$key] = 1; } } else { $fields[$name] = 1; } } $fields['state_province'] = $fields['country'] = $fields['email'] = 1; $contact = $this->_params = $this->controller->exportValues('Main'); foreach ($fields as $name => $dontCare) { if ($name == 'onbehalf') { foreach ($dontCare as $key => $value) { //$defaults[$key] = $contact['onbehalf'][$key]; if (isset($contact['onbehalf'][$key])) { $defaults[$key] = $contact['onbehalf'][$key]; } if (isset($contact['onbehalf']["{$key}_id"])) { $defaults["{$key}_id"] = $contact['onbehalf']["{$key}_id"]; } } } elseif (isset($contact[$name])) { $defaults[$name] = $contact[$name]; if (substr($name, 0, 7) == 'custom_') { $timeField = "{$name}_time"; if (isset($contact[$timeField])) { $defaults[$timeField] = $contact[$timeField]; } } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && CRM_Utils_Array::value($name . '_custom', $contact)) { $defaults[$name . '_custom'] = $contact[$name . '_custom']; } } } // now fix all state country selectors CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults); $this->_submitValues = array_merge($this->_submitValues, $defaults); $this->setDefaults($defaults); $values['entity_id'] = $this->_id; $values['entity_table'] = 'civicrm_contribution_page'; CRM_Friend_BAO_Friend::retrieve($values, $data); $tellAFriend = FALSE; if ($this->_pcpId) { if ($this->_pcpBlock['is_tellfriend_enabled']) { $this->assign('friendText', ts('Tell a Friend')); $subUrl = "eid={$this->_pcpId}&blockId={$this->_pcpBlock['id']}&pcomponent=pcp"; $tellAFriend = TRUE; } } elseif (CRM_Utils_Array::value('is_active', $data)) { $friendText = $data['title']; $this->assign('friendText', $friendText); $subUrl = "eid={$this->_id}&pcomponent=contribute"; $tellAFriend = TRUE; } if ($tellAFriend) { if ($this->_action & CRM_Core_Action::PREVIEW) { $url = CRM_Utils_System::url("civicrm/friend", "reset=1&action=preview&{$subUrl}"); } else { $url = CRM_Utils_System::url("civicrm/friend", "reset=1&{$subUrl}"); } $this->assign('friendURL', $url); } $this->freeze(); // can we blow away the session now to prevent hackery // CRM-9491 $this->controller->reset(); }
/** * Build the form object. */ public function buildQuickForm() { $this->assignToTemplate(); $params = $this->_params; // make sure we have values for it if (!empty($this->_values['honoree_profile_id']) && !empty($params['soft_credit_type_id'])) { $honorName = NULL; $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]); CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor']); $fieldTypes = array('Contact'); $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($this->_values['honoree_profile_id']); $this->buildCustom($this->_values['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes); } $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values)); $amount_block_is_active = $this->get('amount_block_is_active'); $this->assign('amount_block_is_active', $amount_block_is_active); $invoiceSettings = Civi::settings()->get('contribution_invoice_settings'); $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings); if ($invoicing) { $getTaxDetails = FALSE; $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings); foreach ($this->_lineItem as $key => $value) { foreach ($value as $v) { if (isset($v['tax_rate'])) { if ($v['tax_rate'] != '') { $getTaxDetails = TRUE; } } } } $this->assign('getTaxDetails', $getTaxDetails); $this->assign('taxTerm', $taxTerm); $this->assign('totalTaxAmount', $params['tax_amount']); } if (!empty($params['selectProduct']) && $params['selectProduct'] != 'no_thanks') { $option = CRM_Utils_Array::value('options_' . $params['selectProduct'], $params); $productID = $params['selectProduct']; CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option); $this->set('productID', $productID); $this->set('option', $option); } $config = CRM_Core_Config::singleton(); if (in_array('CiviMember', $config->enableComponents)) { if (isset($params['selectMembership']) && $params['selectMembership'] != 'no_thanks') { $this->buildMembershipBlock($this->_membershipContactID, FALSE, $params['selectMembership'], FALSE); if (!empty($params['auto_renew'])) { $this->assign('auto_renew', TRUE); } } else { $this->assign('membershipBlock', FALSE); } } $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE); $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE); if (!empty($this->_values['onbehalf_profile_id']) && !empty($params['onbehalf'])) { $fieldTypes = array('Contact', 'Organization'); $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization'); $fieldTypes = array_merge($fieldTypes, $contactSubType); if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) { $fieldTypes = array_merge($fieldTypes, array('Membership')); } else { $fieldTypes = array_merge($fieldTypes, array('Contribution')); } $this->buildCustom($this->_values['onbehalf_profile_id'], 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes); } $this->_separateMembershipPayment = $this->get('separateMembershipPayment'); $this->assign('is_separate_payment', $this->_separateMembershipPayment); if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) { $this->assign('lineItem', $this->_lineItem); } else { $this->assign('is_quick_config', 1); $this->_params['is_quick_config'] = 1; } $this->assign('priceSetID', $this->_priceSetId); $paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(FALSE, NULL, 'name'); if ($this->_paymentProcessor && $this->_paymentProcessor['payment_processor_type_id'] == CRM_Utils_Array::key('Google_Checkout', $paymentProcessorType) && !$this->_params['is_pay_later'] && !($this->_amount == 0)) { $this->_checkoutButtonName = $this->getButtonName('next', 'checkout'); $this->add('image', $this->_checkoutButtonName, $this->_paymentProcessor['url_button'], array('class' => 'crm-form-submit')); $this->addButtons(array(array('type' => 'back', 'name' => ts('Go Back')))); } else { // The concept of contributeMode is deprecated. // the is_monetary concept probably should be too as it can be calculated from // the existence of 'amount' & seems fragile. if ($this->_contributeMode == 'notify' || !$this->_values['is_monetary'] || $this->_amount <= 0.0 || $this->_params['is_pay_later'] || $this->_separateMembershipPayment && $this->_amount <= 0.0) { $contribButton = ts('Continue'); $this->assign('button', ts('Continue')); } else { $contribButton = ts('Make Contribution'); $this->assign('button', ts('Make Contribution')); } $this->addButtons(array(array('type' => 'next', 'name' => $contribButton, 'spacing' => ' ', 'isDefault' => TRUE, 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');")), array('type' => 'back', 'name' => ts('Go Back')))); } $defaults = array(); $fields = array_fill_keys(array_keys($this->_fields), 1); $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1; $contact = $this->_params; foreach ($fields as $name => $dontCare) { // Recursively set defaults for nested fields if (isset($contact[$name]) && is_array($contact[$name]) && ($name == 'onbehalf' || $name == 'honor')) { foreach ($contact[$name] as $fieldName => $fieldValue) { if (is_array($fieldValue) && !in_array($this->_fields[$name][$fieldName]['html_type'], array('Multi-Select', 'AdvMulti-Select'))) { foreach ($fieldValue as $key => $value) { $defaults["{$name}[{$fieldName}][{$key}]"] = $value; } } else { $defaults["{$name}[{$fieldName}]"] = $fieldValue; } } } elseif (isset($contact[$name])) { $defaults[$name] = $contact[$name]; if (substr($name, 0, 7) == 'custom_') { $timeField = "{$name}_time"; if (isset($contact[$timeField])) { $defaults[$timeField] = $contact[$timeField]; } if (isset($contact["{$name}_id"])) { $defaults["{$name}_id"] = $contact["{$name}_id"]; } } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && !empty($contact[$name . '_custom'])) { $defaults[$name . '_custom'] = $contact[$name . '_custom']; } } } $this->assign('useForMember', $this->get('useForMember')); $this->setDefaults($defaults); $this->freeze(); }
/** * Add onbehalf/honoree profile fields and native module fields. * * @param int $id * @param CRM_Core_Form $form */ public function buildComponentForm($id, $form) { if (empty($id)) { return; } $contactID = $this->getContactID(); foreach (array('soft_credit', 'on_behalf') as $module) { if ($module == 'soft_credit') { if (empty($form->_values['honoree_profile_id'])) { 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'); } } } } }
/** * global validation rules for the form * * @param array $fields posted values of the form * * @return array list of errors to be posted back to the form * @static * @access public */ static function formRule(&$fields, &$files, $self) { $is_required = CRM_Utils_Array::value('is_required', $fields, false); $is_registration = CRM_Utils_Array::value('is_registration', $fields, false); $is_view = CRM_Utils_Array::value('is_view', $fields, false); $in_selector = CRM_Utils_Array::value('in_selector', $fields, false); $is_searchable = CRM_Utils_Array::value('is_searchable', $fields, false); $visibility = CRM_Utils_Array::value('visibility', $fields, false); $is_active = CRM_Utils_Array::value('is_active', $fields, false); $errors = array(); if ($is_view && $is_registration) { $errors['is_registration'] = ts('View Only cannot be selected if this field is to be included on the registration form'); } if ($is_view && $is_required) { $errors['is_view'] = ts('A View Only field cannot be required'); } $fieldName = $fields['field_name'][0]; if (!$fieldName) { $errors['field_name'] = ts('Please select a field name'); } if ($in_selector && in_array($fieldName, array('Contribution', 'Participant', 'Membership'))) { $errors['in_selector'] = ts("'In Selector' cannot be checked for %1 fields.", array(1 => $fieldName)); } if (!empty($fields['field_id'])) { //get custom field id $customFieldId = explode('_', $fieldName); if ($customFieldId[0] == 'custom') { $customField =& new CRM_Core_DAO_CustomField(); $customField->id = $customFieldId[1]; $customField->find(true); if (!$customField->is_active && $is_active) { $errors['field_name'] = ts('Cannot set this field "Active" since the selected custom field is disabled.'); } } } //check profile is configured for double option process //adding group field, email field should be present in the group //fixed for issue CRM-2861 & CRM-4153 $config =& CRM_Core_Config::singleton(); if ($config->profileDoubleOptIn) { if ($fields['field_name'][1] == 'group') { require_once 'CRM/Core/BAO/UFField.php'; $dao =& new CRM_Core_BAO_UFField(); $dao->uf_group_id = $fields['group_id']; $dao->find(); $emailField = false; while ($dao->fetch()) { //check email field is present in the group if ($dao->field_name == 'email') { $emailField = true; } } if (!$emailField) { $disableSetting = "define( 'CIVICRM_PROFILE_DOUBLE_OPTIN' , 0 );"; $errors['field_name'] = ts('Your site is currently configured to require double-opt in when users join (subscribe) to Group(s) via a Profile form. In this mode, you need to include an Email field in a Profile BEFORE you can add the Group(s) field. This ensures that an opt-in confirmation email can be sent. Your site administrator can disable double opt-in by adding this line to the CiviCRM settings file: <em>%1</em>', array(1 => $disableSetting)); } } } //fix for CRM-3037 $fieldType = $fields['field_name'][0]; //get the group type. $groupType = CRM_Core_BAO_UFGroup::calculateGroupType($self->_gid, CRM_Utils_Array::value('field_id', $fields)); switch ($fieldType) { case 'Individual': if (in_array('Household', $groupType) || in_array('Organization', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Individual with combination of Household or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Household': if (in_array('Individual', $groupType) || in_array('Organization', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Household with combination of Individual or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Organization': if (in_array('Household', $groupType) || in_array('Individual', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Organization with combination of Household or Individual'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Participant': if (in_array('Membership', $groupType) || in_array('Contribution', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Participant with combination of Membership or Contribution or Household or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Contribution': if (in_array('Participant', $groupType) || in_array('Membership', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Contribution with combination of Membership or Participant or Household or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Membership': if (in_array('Participant', $groupType) || in_array('Contribution', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Membership with combination of Participant or Contribution or Household or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; default: $profileType = CRM_Core_BAO_UFField::getProfileType($fields['group_id'], true, false, true); if (CRM_Contact_BAO_ContactType::isaSubType($fieldType)) { if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { if ($fieldType != $profileType) { $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(1 => $fieldType, 2 => $profileType)); } } else { $basicType = CRM_Contact_BAO_ContactType::getBasicType($fieldType); if ($profileType && $profileType != $basicType && $profileType != 'Contact') { $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(1 => $fieldType, 2 => $profileType)); } } } elseif ($fields['field_name'][1] == 'contact_sub_type' && !in_array($profileType, array('Individual', 'Household', 'Organization')) && !in_array($profileType, CRM_Contact_BAO_ContactType::subTypes())) { $errors['field_name'] = ts('Cannot add or update profile field Contact Subtype as profile type is not one of Individual, Household or Organization.'); } } return empty($errors) ? true : $errors; }
/** * Test del() with valid data * success expected */ public function testDel() { $params = array('label' => 'indiviSubType', 'name' => 'indiviSubType', 'parent_id' => 1, 'is_active' => 1); $subtype = CRM_Contact_BAO_ContactType::add($params); $del = CRM_Contact_BAO_ContactType::del($subtype->id); $result = CRM_Contact_BAO_ContactType::subTypes(); $this->assertEquals($del, TRUE); $this->assertEquals(in_array($subtype->name, $result), TRUE); }
/** * Build the form object. */ public function buildQuickForm() { $this->_first = TRUE; $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage'); // financial Type $this->addSelect('financial_type_id', array(), TRUE); // name $this->add('text', 'title', ts('Title'), $attributes['title'], TRUE); //CRM-7362 --add campaigns. CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values)); $this->add('wysiwyg', 'intro_text', ts('Introductory Message'), $attributes['intro_text']); $this->add('wysiwyg', 'footer_text', ts('Footer Message'), $attributes['footer_text']); //Register schema which will be used for OnBehalOf and HonorOf profile Selector CRM_UF_Page_ProfileEditor::registerSchemas(array('OrganizationModel', 'HouseholdModel')); // is on behalf of an organization ? $this->addElement('checkbox', 'is_organization', ts('Allow individuals to contribute and / or signup for membership on behalf of an organization?'), NULL, array('onclick' => "showHideByValue('is_organization',true,'for_org_text','table-row','radio',false);showHideByValue('is_organization',true,'for_org_option','table-row','radio',false);")); //CRM-15787 - If applicable, register 'membership_1' $member = CRM_Member_BAO_Membership::getMembershipBlock($this->_id); $coreTypes = array('Contact', 'Organization'); $entities[] = array('entity_name' => array('contact_1'), 'entity_type' => 'OrganizationModel'); if ($member && $member['is_active']) { $coreTypes[] = 'Membership'; $entities[] = array('entity_name' => array('membership_1'), 'entity_type' => 'MembershipModel'); } $allowCoreTypes = array_merge($coreTypes, CRM_Contact_BAO_ContactType::subTypes('Organization')); $allowSubTypes = array(); $this->addProfileSelector('onbehalf_profile_id', ts('Organization Profile'), $allowCoreTypes, $allowSubTypes, $entities); $options = array(); $options[] = $this->createElement('radio', NULL, NULL, ts('Optional'), 1); $options[] = $this->createElement('radio', NULL, NULL, ts('Required'), 2); $this->addGroup($options, 'is_for_organization', ''); $this->add('textarea', 'for_organization', ts('On behalf of Label'), array('rows' => 2, 'cols' => 50)); // collect goal amount $this->add('text', 'goal_amount', ts('Goal Amount'), array('size' => 8, 'maxlength' => 12)); $this->addRule('goal_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money'); // is confirmation page enabled? $this->addElement('checkbox', 'is_confirm_enabled', ts('Use a confirmation page?')); // is this page shareable through social media ? $this->addElement('checkbox', 'is_share', ts('Allow sharing through social media?')); // is this page active ? $this->addElement('checkbox', 'is_active', ts('Is this Online Contribution Page Active?')); // should the honor be enabled $this->addElement('checkbox', 'honor_block_is_active', ts('Honoree Section Enabled'), NULL, array('onclick' => "showHonor()")); $this->add('text', 'honor_block_title', ts('Honoree Section Title'), array('maxlength' => 255, 'size' => 45)); $this->add('textarea', 'honor_block_text', ts('Honoree Introductory Message'), array('rows' => 2, 'cols' => 50)); $this->addSelect('soft_credit_types', array('label' => ts('Honor Types'), 'entity' => 'ContributionSoft', 'field' => 'soft_credit_type_id', 'multiple' => TRUE, 'class' => 'huge')); $entities = array(array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel')); $allowCoreTypes = array_merge(array('Contact', 'Individual', 'Organization', 'Household'), CRM_Contact_BAO_ContactType::subTypes('Individual')); $allowSubTypes = array(); $this->addProfileSelector('honoree_profile', ts('Honoree Profile'), $allowCoreTypes, $allowSubTypes, $entities); if (!empty($this->_submitValues['honor_block_is_active'])) { $this->addRule('soft_credit_types', ts('At least one value must be selected if Honor Section is active'), 'required'); $this->addRule('honoree_profile', ts('Please select a profile used for honoree'), 'required'); } // add optional start and end dates $this->addDateTime('start_date', ts('Start Date')); $this->addDateTime('end_date', ts('End Date')); $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Settings', 'formRule'), $this); parent::buildQuickForm(); }