/** * Add PCP form elements to a form. * * @param int $pcpId * @param CRM_Core_Page $page * @param null $elements */ public static function buildPcp($pcpId, &$page, &$elements = NULL) { $prms = array('id' => $pcpId); CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo); if ($pcpSupporter = CRM_PCP_BAO_PCP::displayName($pcpId)) { if ($pcpInfo['page_type'] == 'event') { $pcp_supporter_text = ts('This event registration is being made thanks to the efforts of <strong>%1</strong>, who supports our campaign. ', array(1 => $pcpSupporter)); $text = CRM_PCP_BAO_PCP::getPcpBlockStatus($pcpInfo['page_id'], 'event'); if (!empty($text)) { $pcp_supporter_text .= "You can support it as well - once you complete the registration, you will be able to create your own Personal Campaign Page!"; } } else { $pcp_supporter_text = ts('This contribution is being made thanks to the efforts of <strong>%1</strong>, who supports our campaign. ', array(1 => $pcpSupporter)); $text = CRM_PCP_BAO_PCP::getPcpBlockStatus($pcpInfo['page_id'], 'contribute'); if (!empty($text)) { $pcp_supporter_text .= "You can support it as well - once you complete the donation, you will be able to create your own Personal Campaign Page!"; } } $page->assign('pcpSupporterText', $pcp_supporter_text); } $page->assign('pcp', TRUE); // build honor roll fields for registration form if supporter has honor roll enabled for their PCP if ($pcpInfo['is_honor_roll']) { $page->assign('is_honor_roll', TRUE); $page->add('checkbox', 'pcp_display_in_roll', ts('Show my support in the public honor roll'), NULL, NULL, array('onclick' => "showHideByValue('pcp_display_in_roll','','nameID|nickID|personalNoteID','block','radio',false); pcpAnonymous( );")); $extraOption = array('onclick' => "return pcpAnonymous( );"); $elements = array(); $elements[] =& $page->createElement('radio', NULL, '', ts('Include my name and message'), 0, $extraOption); $elements[] =& $page->createElement('radio', NULL, '', ts('List my support anonymously'), 1, $extraOption); $page->addGroup($elements, 'pcp_is_anonymous', NULL, ' '); $page->_defaults['pcp_is_anonymous'] = 0; $page->add('text', 'pcp_roll_nickname', ts('Name'), array('maxlength' => 30)); $page->add('textarea', "pcp_personal_note", ts('Personal Note'), array('style' => 'height: 3em; width: 40em;')); } else { $page->assign('is_honor_roll', FALSE); } }
/** * Global validation rules for the form. * * @param array $fields * Posted values of the form. * * @param $values * @param int $mappingTypeId * * @return array * list of errors to be posted back to the form */ public static function formRule($fields, $values, $mappingTypeId) { $errors = array(); if (!empty($fields['saveMapping']) && !empty($fields['_qf_Map_next'])) { $nameField = CRM_Utils_Array::value('saveMappingName', $fields); if (empty($nameField)) { $errors['saveMappingName'] = ts('Name is required to save Export Mapping'); } else { //check for Duplicate mappingName if (CRM_Core_BAO_Mapping::checkMapping($nameField, $mappingTypeId)) { $errors['saveMappingName'] = ts('Duplicate Export Mapping Name'); } } } if (!empty($errors)) { $_flag = 1; $assignError = new CRM_Core_Page(); $assignError->assign('mappingDetailsError', $_flag); return $errors; } else { return TRUE; } }
/** * 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) { $errors = array(); if (!array_key_exists('savedMapping', $fields)) { $importKeys = array(); foreach ($fields['mapper'] as $mapperPart) { $importKeys[] = $mapperPart[0]; } // FIXME: should use the schema titles, not redeclare them $requiredFields = array('membership_contact_id' => ts('Contact ID'), 'membership_type_id' => ts('Membership Type'), 'membership_start_date' => ts('Membership Start Date')); $contactTypeId = $self->get('contactType'); $contactTypes = array(CRM_Import_Parser::CONTACT_INDIVIDUAL => 'Individual', CRM_Import_Parser::CONTACT_HOUSEHOLD => 'Household', CRM_Import_Parser::CONTACT_ORGANIZATION => 'Organization'); $params = array('used' => 'Unsupervised', 'contact_type' => $contactTypes[$contactTypeId]); list($ruleFields, $threshold) = CRM_Dedupe_BAO_RuleGroup::dedupeRuleFieldsWeight($params); $weightSum = 0; foreach ($importKeys as $key => $val) { if (array_key_exists($val, $ruleFields)) { $weightSum += $ruleFields[$val]; } } $fieldMessage = ''; foreach ($ruleFields as $field => $weight) { $fieldMessage .= ' ' . $field . '(weight ' . $weight . ')'; } foreach ($requiredFields as $field => $title) { if (!in_array($field, $importKeys)) { if ($field == 'membership_contact_id') { if (($weightSum >= $threshold || in_array('external_identifier', $importKeys)) && $self->_onDuplicate != CRM_Import_Parser::DUPLICATE_UPDATE || in_array('membership_id', $importKeys)) { continue; } else { if (!isset($errors['_qf_default'])) { $errors['_qf_default'] = ''; } $errors['_qf_default'] .= ts('Missing required contact matching fields.') . " {$fieldMessage} " . ts('(Sum of all weights should be greater than or equal to threshold: %1).', array(1 => $threshold)) . ' ' . ts('(OR Membership ID if update mode.)') . '<br />'; } } else { if (!isset($errors['_qf_default'])) { $errors['_qf_default'] = ''; } $errors['_qf_default'] .= ts('Missing required field: %1', array(1 => $title)) . '<br />'; } } } } if (!empty($fields['saveMapping'])) { $nameField = CRM_Utils_Array::value('saveMappingName', $fields); if (empty($nameField)) { $errors['saveMappingName'] = ts('Name is required to save Import Mapping'); } else { $mappingTypeId = CRM_Core_OptionGroup::getValue('mapping_type', 'Import Membership', 'name'); if (CRM_Core_BAO_Mapping::checkMapping($nameField, $mappingTypeId)) { $errors['saveMappingName'] = ts('Duplicate Import Membership Mapping Name'); } } } if (!empty($errors)) { if (!empty($errors['saveMappingName'])) { $_flag = 1; $assignError = new CRM_Core_Page(); $assignError->assign('mappingDetailsError', $_flag); } return $errors; } return TRUE; }
/** * Add urls for display in the actions menu. * @param CRM_Core_Page $obj * @param int $cid */ public static function addUrls(&$obj, $cid) { $uid = CRM_Core_BAO_UFMatch::getUFId($cid); if ($uid) { $userRecordUrl = CRM_Core_Config::singleton()->userSystem->getUserRecordUrl($cid); $obj->assign('userRecordUrl', $userRecordUrl); $obj->assign('userRecordId', $uid); } elseif (CRM_Core_Config::singleton()->userSystem->checkPermissionAddUser()) { $userAddUrl = CRM_Utils_System::url('civicrm/contact/view/useradd', 'reset=1&action=add&cid=' . $cid); $obj->assign('userAddUrl', $userAddUrl); } if (CRM_Core_Permission::check('access Contact Dashboard')) { $dashboardURL = CRM_Utils_System::url('civicrm/user', "reset=1&id={$cid}"); $obj->assign('dashboardURL', $dashboardURL); } // See if other modules want to add links to the activtity bar $hookLinks = array(); CRM_Utils_Hook::links('view.contact.activity', 'Contact', $cid, $hookLinks, CRM_Core_DAO::$_nullObject, CRM_Core_DAO::$_nullObject); if (is_array($hookLinks)) { $obj->assign('hookLinks', $hookLinks); } }
/** * 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) { $errors = array(); // define so we avoid notices below $errors['_qf_default'] = ''; $fieldMessage = NULL; if (!array_key_exists('savedMapping', $fields)) { $importKeys = array(); foreach ($fields['mapper'] as $mapperPart) { $importKeys[] = $mapperPart[0]; } // FIXME: should use the schema titles, not redeclare them $requiredFields = array('target_contact_id' => ts('Contact ID'), 'activity_date_time' => ts('Activity Date'), 'activity_subject' => ts('Activity Subject'), 'activity_type_id' => ts('Activity Type Id')); $params = array('used' => 'Unsupervised', 'contact_type' => 'Individual'); list($ruleFields, $threshold) = CRM_Dedupe_BAO_RuleGroup::dedupeRuleFieldsWeight($params); $weightSum = 0; foreach ($importKeys as $key => $val) { if (array_key_exists($val, $ruleFields)) { $weightSum += $ruleFields[$val]; } } foreach ($ruleFields as $field => $weight) { $fieldMessage .= ' ' . $field . '(weight ' . $weight . ')'; } foreach ($requiredFields as $field => $title) { if (!in_array($field, $importKeys)) { if ($field == 'target_contact_id') { if ($weightSum >= $threshold || in_array('external_identifier', $importKeys)) { continue; } else { $errors['_qf_default'] .= ts('Missing required contact matching fields.') . $fieldMessage . ' ' . ts('(Sum of all weights should be greater than or equal to threshold: %1).', array(1 => $threshold)) . '<br />'; } } elseif ($field == 'activity_type_id') { if (in_array('activity_label', $importKeys)) { continue; } else { $errors['_qf_default'] .= ts('Missing required field: Provide %1 or %2', array(1 => $title, 2 => 'Activity Type Label')) . '<br />'; } } else { $errors['_qf_default'] .= ts('Missing required field: %1', array(1 => $title)) . '<br />'; } } } } if (!empty($fields['saveMapping'])) { $nameField = CRM_Utils_Array::value('saveMappingName', $fields); if (empty($nameField)) { $errors['saveMappingName'] = ts('Name is required to save Import Mapping'); } else { $mappingTypeId = CRM_Core_OptionGroup::getValue('mapping_type', 'Import Activity', 'name'); if (CRM_Core_BAO_Mapping::checkMapping($nameField, $mappingTypeId)) { $errors['saveMappingName'] = ts('Duplicate Import Mapping Name'); } } } if (empty($errors['_qf_default'])) { unset($errors['_qf_default']); } if (!empty($errors)) { if (!empty($errors['saveMappingName'])) { $_flag = 1; $assignError = new CRM_Core_Page(); $assignError->assign('mappingDetailsError', $_flag); } return $errors; } return TRUE; }
/** * 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) { $errors = array(); $fieldMessage = NULL; if (!array_key_exists('savedMapping', $fields)) { $importKeys = array(); foreach ($fields['mapper'] as $mapperPart) { $importKeys[] = $mapperPart[0]; } // FIXME: should use the schema titles, not redeclare them $requiredFields = array('participant_contact_id' => ts('Contact ID'), 'event_id' => ts('Event ID')); $contactTypeId = $self->get('contactType'); $contactTypes = array(CRM_Import_Parser::CONTACT_INDIVIDUAL => 'Individual', CRM_Import_Parser::CONTACT_HOUSEHOLD => 'Household', CRM_Import_Parser::CONTACT_ORGANIZATION => 'Organization'); $params = array('used' => 'Unsupervised', 'contact_type' => $contactTypes[$contactTypeId]); list($ruleFields, $threshold) = CRM_Dedupe_BAO_RuleGroup::dedupeRuleFieldsWeight($params); $weightSum = 0; foreach ($importKeys as $key => $val) { if (array_key_exists($val, $ruleFields)) { $weightSum += $ruleFields[$val]; } } foreach ($ruleFields as $field => $weight) { $fieldMessage .= ' ' . $field . '(weight ' . $weight . ')'; } foreach ($requiredFields as $field => $title) { if (!in_array($field, $importKeys)) { if ($field == 'participant_contact_id') { if ($weightSum >= $threshold || in_array('external_identifier', $importKeys) || in_array('participant_id', $importKeys)) { continue; } if ($self->_onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) { $errors['_qf_default'] .= ts('Missing required field: Provide Particiapnt ID') . '<br />'; } else { $errors['_qf_default'] .= ts('Missing required contact matching fields.') . " {$fieldMessage} " . ts('(Sum of all weights should be greater than or equal to threshold: %1).', array(1 => $threshold)) . ' ' . ts('Or Provide Contact Id or External Identifier.') . '<br />'; } } elseif (!in_array('event_title', $importKeys)) { $errors['_qf_default'] .= ts('Missing required field: Provide %1 or %2', array(1 => $title, 2 => 'Event Title')) . '<br />'; } } } } if (CRM_Utils_Array::value('saveMapping', $fields)) { $nameField = CRM_Utils_Array::value('saveMappingName', $fields); if (empty($nameField)) { $errors['saveMappingName'] = ts('Name is required to save Import Mapping'); } else { $mappingTypeId = CRM_Core_OptionGroup::getValue('mapping_type', 'Import Participant', 'name'); if (CRM_Core_BAO_Mapping::checkMapping($nameField, $mappingTypeId)) { $errors['saveMappingName'] = ts('Duplicate Import Participant Mapping Name'); } } } //display Error if loaded mapping is not selected if (array_key_exists('loadMapping', $fields)) { $getMapName = CRM_Utils_Array::value('savedMapping', $fields); if (empty($getMapName)) { $errors['savedMapping'] = ts('Select saved mapping'); } } if (!empty($errors)) { if (!empty($errors['saveMappingName'])) { $_flag = 1; $assignError = new CRM_Core_Page(); $assignError->assign('mappingDetailsError', $_flag); } return $errors; } return TRUE; }
/** * 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) { $errors = array(); $fieldMessage = NULL; $contactORContributionId = $self->_onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE ? 'contribution_id' : 'contribution_contact_id'; if (!array_key_exists('savedMapping', $fields)) { $importKeys = array(); foreach ($fields['mapper'] as $mapperPart) { $importKeys[] = $mapperPart[0]; } $contactTypeId = $self->get('contactType'); $contactTypes = array(CRM_Import_Parser::CONTACT_INDIVIDUAL => 'Individual', CRM_Import_Parser::CONTACT_HOUSEHOLD => 'Household', CRM_Import_Parser::CONTACT_ORGANIZATION => 'Organization'); $params = array('used' => 'Unsupervised', 'contact_type' => isset($contactTypes[$contactTypeId]) ? $contactTypes[$contactTypeId] : ''); list($ruleFields, $threshold) = CRM_Dedupe_BAO_RuleGroup::dedupeRuleFieldsWeight($params); $weightSum = 0; foreach ($importKeys as $key => $val) { if (array_key_exists($val, $ruleFields)) { $weightSum += $ruleFields[$val]; } if ($val == "soft_credit") { $mapperKey = CRM_Utils_Array::key('soft_credit', $importKeys); if (empty($fields['mapper'][$mapperKey][1])) { if (empty($errors['_qf_default'])) { $errors['_qf_default'] = ''; } $errors['_qf_default'] .= ts('Missing required fields: Soft Credit') . '<br />'; } } } foreach ($ruleFields as $field => $weight) { $fieldMessage .= ' ' . $field . '(weight ' . $weight . ')'; } // FIXME: should use the schema titles, not redeclare them $requiredFields = array($contactORContributionId == 'contribution_id' ? 'contribution_id' : 'contribution_contact_id' => $contactORContributionId == 'contribution_id' ? ts('Contribution ID') : ts('Contact ID'), 'total_amount' => ts('Total Amount'), 'financial_type' => ts('Financial Type')); foreach ($requiredFields as $field => $title) { if (!in_array($field, $importKeys)) { if (empty($errors['_qf_default'])) { $errors['_qf_default'] = ''; } if ($field == $contactORContributionId) { if (!($weightSum >= $threshold || in_array('external_identifier', $importKeys)) && $self->_onDuplicate != CRM_Import_Parser::DUPLICATE_UPDATE) { $errors['_qf_default'] .= ts('Missing required contact matching fields.') . " {$fieldMessage} " . ts('(Sum of all weights should be greater than or equal to threshold: %1).', array(1 => $threshold)) . '<br />'; } elseif ($self->_onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE && !(in_array('invoice_id', $importKeys) || in_array('trxn_id', $importKeys) || in_array('contribution_id', $importKeys))) { $errors['_qf_default'] .= ts('Invoice ID or Transaction ID or Contribution ID are required to match to the existing contribution records in Update mode.') . '<br />'; } } else { $errors['_qf_default'] .= ts('Missing required field: %1', array(1 => $title)) . '<br />'; } } } //at least one field should be mapped during update. if ($self->_onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) { $atleastOne = FALSE; foreach ($self->_mapperFields as $key => $field) { if (in_array($key, $importKeys) && !in_array($key, array('doNotImport', 'contribution_id', 'invoice_id', 'trxn_id'))) { $atleastOne = TRUE; break; } } if (!$atleastOne) { $errors['_qf_default'] .= ts('At least one contribution field needs to be mapped for update during update mode.') . '<br />'; } } } if (!empty($fields['saveMapping'])) { $nameField = CRM_Utils_Array::value('saveMappingName', $fields); if (empty($nameField)) { $errors['saveMappingName'] = ts('Name is required to save Import Mapping'); } else { $mappingTypeId = CRM_Core_OptionGroup::getValue('mapping_type', 'Import Contribution', 'name'); if (CRM_Core_BAO_Mapping::checkMapping($nameField, $mappingTypeId)) { $errors['saveMappingName'] = ts('Duplicate Import Contribution Mapping Name'); } } } if (!empty($errors)) { if (!empty($errors['saveMappingName'])) { $_flag = 1; $assignError = new CRM_Core_Page(); $assignError->assign('mappingDetailsError', $_flag); } if (!empty($errors['_qf_default'])) { CRM_Core_Session::setStatus($errors['_qf_default'], ts("Error"), "error"); return $errors; } } return TRUE; }
/** * 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 */ public static function formRule($fields) { $errors = array(); $fieldMessage = NULL; if (!array_key_exists('savedMapping', $fields)) { $importKeys = array(); foreach ($fields['mapper'] as $mapperPart) { $importKeys[] = $mapperPart[0]; } $requiredFields = array('contact_id' => ts('Contact ID')); foreach ($requiredFields as $field => $title) { if (!in_array($field, $importKeys)) { if (!isset($errors['_qf_default'])) { $errors['_qf_default'] = ''; } $errors['_qf_default'] .= ts('Missing required field: %1', array(1 => $title)); } } } if (!empty($fields['saveMapping'])) { $nameField = CRM_Utils_Array::value('saveMappingName', $fields); if (empty($nameField)) { $errors['saveMappingName'] = ts('Name is required to save Import Mapping'); } else { $mappingTypeId = CRM_Core_OptionGroup::getValue('mapping_type', 'Import Multi value custom data', 'name'); if (CRM_Core_BAO_Mapping::checkMapping($nameField, $mappingTypeId)) { $errors['saveMappingName'] = ts('Duplicate ' . $self->_mappingType . 'Mapping Name'); } } } //display Error if loaded mapping is not selected if (array_key_exists('loadMapping', $fields)) { $getMapName = CRM_Utils_Array::value('savedMapping', $fields); if (empty($getMapName)) { $errors['savedMapping'] = ts('Select saved mapping'); } } if (!empty($errors)) { if (!empty($errors['saveMappingName'])) { $_flag = 1; $assignError = new CRM_Core_Page(); $assignError->assign('mappingDetailsError', $_flag); } return $errors; } return TRUE; }
/** * global validation rules for the form * * @param array $fields (referance) posted values of the form * * @return array if errors then list of errors to be posted back to the form, * true otherwise * @static * @access public */ static function formRule($fields, $files, $self) { $default = CRM_Utils_Array::value('default_value', $fields); $errors = array(); //validate field label as well as name. $title = $fields['label']; $name = CRM_Utils_String::munge($title, '_', 64); $gId = $self->_gid; // CRM-7564 $query = 'select count(*) from civicrm_custom_field where ( name like %1 OR label like %2 ) and id != %3 and custom_group_id = %4'; $fldCnt = CRM_Core_DAO::singleValueQuery($query, array(1 => array($name, 'String'), 2 => array($title, 'String'), 3 => array((int) $self->_id, 'Integer'), 4 => array($gId, 'Integer'))); if ($fldCnt) { $errors['label'] = ts('Custom field \'%1\' already exists in Database.', array(1 => $title)); } //checks the given custom field name doesnot start with digit if (!empty($title)) { // gives the ascii value $asciiValue = ord($title[0]); if ($asciiValue >= 48 && $asciiValue <= 57) { $errors['label'] = ts("Field's Name should not start with digit"); } } // ensure that the label is not 'id' if (strtolower($title) == 'id') { $errors['label'] = ts("You cannot use 'id' as a field label."); } if (!isset($fields['data_type'][0]) || !isset($fields['data_type'][1])) { $errors['_qf_default'] = ts('Please enter valid - Data and Input Field Type.'); } $dataType = self::$_dataTypeKeys[$fields['data_type'][0]]; if ($default || $dataType == 'ContactReference') { switch ($dataType) { case 'Int': if (!CRM_Utils_Rule::integer($default)) { $errors['default_value'] = ts('Please enter a valid integer as default value.'); } break; case 'Float': if (!CRM_Utils_Rule::numeric($default)) { $errors['default_value'] = ts('Please enter a valid number as default value.'); } break; case 'Money': if (!CRM_Utils_Rule::money($default)) { $errors['default_value'] = ts('Please enter a valid number value.'); } break; case 'Link': if (!CRM_Utils_Rule::url($default)) { $errors['default_value'] = ts('Please enter a valid link.'); } break; case 'Date': if (!CRM_Utils_Rule::date($default)) { $errors['default_value'] = ts('Please enter a valid date as default value using YYYY-MM-DD format. Example: 2004-12-31.'); } break; case 'Boolean': if ($default != '1' && $default != '0') { $errors['default_value'] = ts('Please enter 1 (for Yes) or 0 (for No) if you want to set a default value.'); } break; case 'Country': if (!empty($default)) { $query = "SELECT count(*) FROM civicrm_country WHERE name = %1 OR iso_code = %1"; $params = array(1 => array($fields['default_value'], 'String')); if (CRM_Core_DAO::singleValueQuery($query, $params) <= 0) { $errors['default_value'] = ts('Invalid default value for country.'); } } break; case 'StateProvince': if (!empty($default)) { $query = "\nSELECT count(*)\n FROM civicrm_state_province\n WHERE name = %1\n OR abbreviation = %1"; $params = array(1 => array($fields['default_value'], 'String')); if (CRM_Core_DAO::singleValueQuery($query, $params) <= 0) { $errors['default_value'] = ts('The invalid default value for State/Province data type'); } } break; case 'ContactReference': if ($fields['filter_selected'] == 'Advance' && CRM_Utils_Array::value('filter', $fields)) { if (strpos($fields['filter'], 'entity=') !== FALSE) { $errors['filter'] = ts("Please do not include entity parameter (entity is always 'contact')"); } elseif (strpos($fields['filter'], 'action=') === FALSE) { $errors['filter'] = ts("Please specify 'action' parameter, it should be 'lookup' or 'get'"); } elseif (strpos($fields['filter'], 'action=get') === FALSE && strpos($fields['filter'], 'action=lookup') === FALSE) { $errors['filter'] = ts("Only 'get' and 'lookup' actions are supported."); } } $self->setDefaults(array('filter_selected', $fields['filter_selected'])); break; } } if (self::$_dataTypeKeys[$fields['data_type'][0]] == 'Date') { if (!$fields['date_format']) { $errors['date_format'] = ts('Please select a date format.'); } } /** Check the option values entered * Appropriate values are required for the selected datatype * Incomplete row checking is also required. */ $_flagOption = $_rowError = 0; $_showHide = new CRM_Core_ShowHideBlocks('', ''); $dataType = self::$_dataTypeKeys[$fields['data_type'][0]]; if (isset($fields['data_type'][1])) { $dataField = $fields['data_type'][1]; } $optionFields = array('Select', 'Multi-Select', 'CheckBox', 'Radio', 'AdvMulti-Select'); if (isset($fields['option_type']) && $fields['option_type'] == 1) { //capture duplicate Custom option values if (!empty($fields['option_value'])) { $countValue = count($fields['option_value']); $uniqueCount = count(array_unique($fields['option_value'])); if ($countValue > $uniqueCount) { $start = 1; while ($start < self::NUM_OPTION) { $nextIndex = $start + 1; while ($nextIndex <= self::NUM_OPTION) { if ($fields['option_value'][$start] == $fields['option_value'][$nextIndex] && !empty($fields['option_value'][$nextIndex])) { $errors['option_value[' . $start . ']'] = ts('Duplicate Option values'); $errors['option_value[' . $nextIndex . ']'] = ts('Duplicate Option values'); $_flagOption = 1; } $nextIndex++; } $start++; } } } //capture duplicate Custom Option label if (!empty($fields['option_label'])) { $countValue = count($fields['option_label']); $uniqueCount = count(array_unique($fields['option_label'])); if ($countValue > $uniqueCount) { $start = 1; while ($start < self::NUM_OPTION) { $nextIndex = $start + 1; while ($nextIndex <= self::NUM_OPTION) { if ($fields['option_label'][$start] == $fields['option_label'][$nextIndex] && !empty($fields['option_label'][$nextIndex])) { $errors['option_label[' . $start . ']'] = ts('Duplicate Option label'); $errors['option_label[' . $nextIndex . ']'] = ts('Duplicate Option label'); $_flagOption = 1; } $nextIndex++; } $start++; } } } for ($i = 1; $i <= self::NUM_OPTION; $i++) { if (!$fields['option_label'][$i]) { if ($fields['option_value'][$i]) { $errors['option_label[' . $i . ']'] = ts('Option label cannot be empty'); $_flagOption = 1; } else { $_emptyRow = 1; } } else { if (!strlen(trim($fields['option_value'][$i]))) { if (!$fields['option_value'][$i]) { $errors['option_value[' . $i . ']'] = ts('Option value cannot be empty'); $_flagOption = 1; } } } if ($fields['option_value'][$i] && $dataType != 'String') { if ($dataType == 'Int') { if (!CRM_Utils_Rule::integer($fields['option_value'][$i])) { $_flagOption = 1; $errors['option_value[' . $i . ']'] = ts('Please enter a valid integer.'); } } elseif ($dataType == 'Money') { if (!CRM_Utils_Rule::money($fields['option_value'][$i])) { $_flagOption = 1; $errors['option_value[' . $i . ']'] = ts('Please enter a valid money value.'); } } else { if (!CRM_Utils_Rule::numeric($fields['option_value'][$i])) { $_flagOption = 1; $errors['option_value[' . $i . ']'] = ts('Please enter a valid number.'); } } } $showBlocks = 'optionField_' . $i; if ($_flagOption) { $_showHide->addShow($showBlocks); $_rowError = 1; } if (!empty($_emptyRow)) { $_showHide->addHide($showBlocks); } else { $_showHide->addShow($showBlocks); } if ($i == self::NUM_OPTION) { $hideBlock = 'additionalOption'; $_showHide->addHide($hideBlock); } $_flagOption = $_emptyRow = 0; } } elseif (isset($dataField) && in_array($dataField, $optionFields) && !in_array($dataType, array('Boolean', 'Country', 'StateProvince'))) { if (!$fields['option_group_id']) { $errors['option_group_id'] = ts('You must select a Multiple Choice Option set if you chose Reuse an existing set.'); } else { $query = "\nSELECT count(*)\nFROM civicrm_custom_field\nWHERE data_type != %1\nAND option_group_id = %2"; $params = array(1 => array(self::$_dataTypeKeys[$fields['data_type'][0]], 'String'), 2 => array($fields['option_group_id'], 'Integer')); $count = CRM_Core_DAO::singleValueQuery($query, $params); if ($count > 0) { $errors['option_group_id'] = ts('The data type of the multiple choice option set you\'ve selected does not match the data type assigned to this field.'); } } } $assignError = new CRM_Core_Page(); if ($_rowError) { $_showHide->addToTemplate(); $assignError->assign('optionRowError', $_rowError); } else { if (isset($fields['data_type'][1])) { switch (self::$_dataToHTML[$fields['data_type'][0]][$fields['data_type'][1]]) { case 'Radio': $_fieldError = 1; $assignError->assign('fieldError', $_fieldError); break; case 'Checkbox': $_fieldError = 1; $assignError->assign('fieldError', $_fieldError); break; case 'Select': $_fieldError = 1; $assignError->assign('fieldError', $_fieldError); break; default: $_fieldError = 0; $assignError->assign('fieldError', $_fieldError); } } for ($idx = 1; $idx <= self::NUM_OPTION; $idx++) { $showBlocks = 'optionField_' . $idx; if (!empty($fields['option_label'][$idx])) { $_showHide->addShow($showBlocks); } else { $_showHide->addHide($showBlocks); } } $_showHide->addToTemplate(); } // we can not set require and view at the same time. if (CRM_Utils_Array::value('is_required', $fields) && CRM_Utils_Array::value('is_view', $fields)) { $errors['is_view'] = ts('Can not set this field Required and View Only at the same time.'); } return empty($errors) ? TRUE : $errors; }
/** * 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 */ public static function formRule($fields) { $errors = array(); if (!empty($fields['saveMapping'])) { $nameField = CRM_Utils_Array::value('saveMappingName', $fields); if (empty($nameField)) { $errors['saveMappingName'] = ts('Name is required to save Import Mapping'); } else { $mappingTypeId = CRM_Core_OptionGroup::getValue('mapping_type', 'Import Contact', 'name'); if (CRM_Core_BAO_Mapping::checkMapping($nameField, $mappingTypeId)) { $errors['saveMappingName'] = ts('Duplicate Import Mapping Name'); } } } $template = CRM_Core_Smarty::singleton(); if (!empty($fields['saveMapping'])) { $template->assign('isCheked', TRUE); } if (!empty($errors)) { $_flag = 1; $assignError = new CRM_Core_Page(); $assignError->assign('mappingDetailsError', $_flag); return $errors; } else { return TRUE; } }
/** * Assign smarty variables to the template that will be used by google api to plot the contacts. * * @param array $ids * @param int $locationId * Location_id. * @param CRM_Core_Page $page * @param bool $addBreadCrumb * @param string $type */ public static function createMapXML($ids, $locationId, &$page, $addBreadCrumb, $type = 'Contact') { $config = CRM_Core_Config::singleton(); CRM_Utils_System::setTitle(ts('Map Location(s)')); $page->assign('query', 'CiviCRM Search Query'); $page->assign('mapProvider', $config->mapProvider); $page->assign('mapKey', urlencode($config->mapAPIKey)); if ($type == 'Contact') { $imageUrlOnly = FALSE; // google needs image url, CRM-6564 if ($config->mapProvider == 'Google' || $config->mapProvider == 'OpenStreetMaps') { $imageUrlOnly = TRUE; } $locations = CRM_Contact_BAO_Contact_Location::getMapInfo($ids, $locationId, $imageUrlOnly); } else { $locations = CRM_Event_BAO_Event::getMapInfo($ids); } if (empty($locations)) { CRM_Core_Error::statusBounce(ts('This address does not contain latitude/longitude information and cannot be mapped.')); } if (empty($config->mapProvider)) { CRM_Core_Error::statusBounce(ts('You need to configure a Mapping Provider before using this feature (Administer > System Settings > Mapping and Geocoding).')); } if ($addBreadCrumb) { $session = CRM_Core_Session::singleton(); $redirect = $session->readUserContext(); if ($type == 'Contact') { $bcTitle = ts('Contact'); } else { $bcTitle = ts('Event Info'); $action = CRM_Utils_Request::retrieve('action', 'String', $page, FALSE); if ($action) { $args = 'reset=1&action=preview&id='; } else { $args = 'reset=1&id='; } $session->pushUserContext(CRM_Utils_System::url('civicrm/event/info', "{$args}{$ids}")); } CRM_Utils_System::appendBreadCrumb($bcTitle, $redirect); } $page->assign_by_ref('locations', $locations); // only issue a javascript warning if we know we will not // mess the poor user with too many warnings if (count($locations) <= 3) { $page->assign('geoCodeWarn', TRUE); } else { $page->assign('geoCodeWarn', FALSE); } $sumLat = $sumLng = 0; $maxLat = $maxLng = -400; $minLat = $minLng = 400; foreach ($locations as $location) { $sumLat += $location['lat']; $sumLng += $location['lng']; if ($location['lat'] > $maxLat) { $maxLat = $location['lat']; } if ($location['lat'] < $minLat) { $minLat = $location['lat']; } if ($location['lng'] > $maxLng) { $maxLng = $location['lng']; } if ($location['lng'] < $minLng) { $minLng = $location['lng']; } } $center = array('lat' => (double) $sumLat / count($locations), 'lng' => (double) $sumLng / count($locations)); $span = array('lat' => (double) ($maxLat - $minLat), 'lng' => (double) ($maxLng - $minLng)); $page->assign_by_ref('center', $center); $page->assign_by_ref('span', $span); }
/** * global validation rules for the form * * @param array $fields (referance) posted values of the form * * @return array if errors then list of errors to be posted back to the form, * true otherwise * @static * @access public */ function formRule(&$fields) { $default = CRM_Utils_Array::value('default_value', $fields); $errors = array(); if ($default) { $dataType = $GLOBALS['_CRM_CUSTOM_FORM_FIELD']['_dataTypeKeys'][$fields['data_type'][0]]; switch ($dataType) { case 'Int': if (!CRM_Utils_Rule::integer($default)) { $errors['default_value'] = ts('Please enter a valid integer as default value.'); } break; case 'Float': case 'Money': if (!CRM_Utils_Rule::numeric($default)) { $errors['default_value'] = ts('Please enter a valid number as default value.'); } break; case 'Date': if (!CRM_Utils_Rule::date($default)) { $errors['default_value'] = ts('Please enter a valid date as default value using YYYY-MM-DD format. Example: 2004-12-31.'); } break; case 'Boolean': if (!CRM_Utils_Rule::integer($default) && ($default != '1' || $default != '0')) { $errors['default_value'] = ts('Please enter 1 or 0 as default value.'); } break; case 'Country': if (!empty($default)) { $fieldCountry = addslashes($fields['default_value']); $query = "SELECT count(*) FROM civicrm_country WHERE name = '{$fieldCountry}' OR iso_code = '{$fieldCountry}'"; if (CRM_Core_DAO::singleValueQuery($query) <= 0) { $errors['default_value'] = ts('Invalid default value for country.'); } } break; case 'StateProvince': if (!empty($default)) { $fieldStateProvince = addslashes($fields['default_value']); $query = "SELECT count(*) FROM civicrm_state_province WHERE name = '{$fieldStateProvince}' OR abbreviation = '{$fieldStateProvince}'"; if (CRM_Core_DAO::singleValueQuery($query) <= 0) { $errors['default_value'] = ts('The invalid default value for State/Province data type'); } } break; } } /** Check the option values entered * Appropriate values are required for the selected datatype * Incomplete row checking is also required. */ if (CRM_CORE_ACTION_ADD) { $_flagOption = $_rowError = 0; $_showHide =& new CRM_Core_ShowHideBlocks('', ''); $dataType = $GLOBALS['_CRM_CUSTOM_FORM_FIELD']['_dataTypeKeys'][$fields['data_type'][0]]; //capture duplicate Custom option values if (!empty($fields['option_value'])) { $countValue = count($fields['option_value']); $uniqueCount = count(array_unique($fields['option_value'])); if ($countValue > $uniqueCount) { $start = 1; while ($start < CRM_CUSTOM_FORM_FIELD_NUM_OPTION) { $nextIndex = $start + 1; while ($nextIndex <= CRM_CUSTOM_FORM_FIELD_NUM_OPTION) { if ($fields['option_value'][$start] == $fields['option_value'][$nextIndex] && !empty($fields['option_value'][$nextIndex])) { $errors['option_value[' . $start . ']'] = ts('Duplicate Option values'); $errors['option_value[' . $nextIndex . ']'] = ts('Duplicate Option values'); $_flagOption = 1; } $nextIndex++; } $start++; } } } //capture duplicate Custom Option label if (!empty($fields['option_label'])) { $countValue = count($fields['option_label']); $uniqueCount = count(array_unique($fields['option_label'])); if ($countValue > $uniqueCount) { $start = 1; while ($start < CRM_CUSTOM_FORM_FIELD_NUM_OPTION) { $nextIndex = $start + 1; while ($nextIndex <= CRM_CUSTOM_FORM_FIELD_NUM_OPTION) { if ($fields['option_label'][$start] == $fields['option_label'][$nextIndex] && !empty($fields['option_label'][$nextIndex])) { $errors['option_label[' . $start . ']'] = ts('Duplicate Option label'); $errors['option_label[' . $nextIndex . ']'] = ts('Duplicate Option label'); $_flagOption = 1; } $nextIndex++; } $start++; } } } for ($i = 1; $i <= CRM_CUSTOM_FORM_FIELD_NUM_OPTION; $i++) { if (!$fields['option_label'][$i]) { if ($fields['option_value'][$i]) { $errors['option_label[' . $i . ']'] = ts('Option label cannot be empty'); $_flagOption = 1; } else { $_emptyRow = 1; } } else { if (!strlen(trim($fields['option_value'][$i]))) { if (!$fields['option_value'][$i]) { $errors['option_value[' . $i . ']'] = ts('Option value cannot be empty'); $_flagOption = 1; } } } if ($fields['option_value'][$i] && $dataType != 'String') { if ($dataType == 'Int') { if (!CRM_Utils_Rule::integer($fields['option_value'][$i])) { $_flagOption = 1; $errors['option_value[' . $i . ']'] = ts('Please enter a valid integer.'); } } else { if (!CRM_Utils_Rule::numeric($fields['option_value'][$i])) { $_flagOption = 1; $errors['option_value[' . $i . ']'] = ts('Please enter a valid number.'); } } } $showBlocks = 'optionField[' . $i . ']'; if ($_flagOption) { $_showHide->addShow($showBlocks); $_rowError = 1; } if ($_emptyRow) { $_showHide->addHide($showBlocks); } else { $_showHide->addShow($showBlocks); } if ($i == CRM_CUSTOM_FORM_FIELD_NUM_OPTION) { $hideBlock = 'additionalOption'; $_showHide->addHide($hideBlock); } $_flagOption = $_emptyRow = 0; } if ($_rowError) { $_showHide->addToTemplate(); CRM_Core_Page::assign('optionRowError', $_rowError); } else { switch ($GLOBALS['_CRM_CUSTOM_FORM_FIELD']['_dataToHTML'][$fields['data_type'][0]][$fields['data_type'][1]]) { case 'Radio': $_fieldError = 1; CRM_Core_Page::assign('fieldError', $_fieldError); break; case 'Checkbox': $_fieldError = 1; CRM_Core_Page::assign('fieldError', $_fieldError); break; case 'Select': $_fieldError = 1; CRM_Core_Page::assign('fieldError', $_fieldError); break; default: $_fieldError = 0; CRM_Core_Page::assign('fieldError', $_fieldError); } for ($idx = 1; $idx <= CRM_CUSTOM_FORM_FIELD_NUM_OPTION; $idx++) { $showBlocks = 'optionField[' . $idx . ']'; if (!empty($fields['option_label'][$idx])) { $_showHide->addShow($showBlocks); } else { $_showHide->addHide($showBlocks); } } $_showHide->addToTemplate(); } } return empty($errors) ? true : $errors; }
/** * 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 * @static * @access public */ static function formRule($fields, $files, $self) { $errors = array(); $fieldMessage = NULL; if (!array_key_exists('savedMapping', $fields)) { $importKeys = array(); foreach ($fields['mapper'] as $mapperPart) { $importKeys[] = $mapperPart[0]; } $contactTypeId = $self->get('contactType'); $contactTypes = array(CRM_Import_Parser::CONTACT_INDIVIDUAL => 'Individual', CRM_Import_Parser::CONTACT_HOUSEHOLD => 'Household', CRM_Import_Parser::CONTACT_ORGANIZATION => 'Organization'); $params = array('used' => 'Unsupervised', 'contact_type' => $contactTypes[$contactTypeId]); list($ruleFields, $threshold) = CRM_Dedupe_BAO_RuleGroup::dedupeRuleFieldsWeight($params); $weightSum = 0; foreach ($importKeys as $key => $val) { if (array_key_exists($val, $ruleFields)) { $weightSum += $ruleFields[$val]; } } foreach ($ruleFields as $field => $weight) { $fieldMessage .= ' ' . $field . '(weight ' . $weight . ')'; } } if (CRM_Utils_Array::value('saveMapping', $fields)) { $nameField = CRM_Utils_Array::value('saveMappingName', $fields); if (empty($nameField)) { $errors['saveMappingName'] = ts('Name is required to save Import Mapping'); } else { $mappingTypeId = CRM_Core_OptionGroup::getValue('mapping_type', $this->_mappingType, 'name'); if (CRM_Core_BAO_Mapping::checkMapping($nameField, $mappingTypeId)) { $errors['saveMappingName'] = ts('Duplicate ' . $this->_mappingType . 'Mapping Name'); } } } //display Error if loaded mapping is not selected if (array_key_exists('loadMapping', $fields)) { $getMapName = CRM_Utils_Array::value('savedMapping', $fields); if (empty($getMapName)) { $errors['savedMapping'] = ts('Select saved mapping'); } } if (!empty($errors)) { if (!empty($errors['saveMappingName'])) { $_flag = 1; $assignError = new CRM_Core_Page(); $assignError->assign('mappingDetailsError', $_flag); } return $errors; } return TRUE; }