/** * @param $form */ function buildForm(&$form) { /** * You can define a custom title for the search form */ $this->setTitle('Find Latest Activities'); /** * Define the search form fields here */ // Allow user to choose which type of contact to limit search on $form->add('select', 'contact_type', ts('Find...'), CRM_Core_SelectValues::contactType()); // Text box for Activity Subject $form->add('text', 'activity_subject', ts('Activity Subject')); // Select box for Activity Type $activityType = array('' => ' - select activity - ') + CRM_Core_PseudoConstant::activityType(); $form->add('select', 'activity_type_id', ts('Activity Type'), $activityType, FALSE); // textbox for Activity Status $activityStatus = array('' => ' - select status - ') + CRM_Core_PseudoConstant::activityStatus(); $form->add('select', 'activity_status_id', ts('Activity Status'), $activityStatus, FALSE); // Activity Date range $form->addDate('start_date', ts('Activity Date From'), FALSE, array('formatType' => 'custom')); $form->addDate('end_date', ts('...through'), FALSE, array('formatType' => 'custom')); // Contact Name field $form->add('text', 'sort_name', ts('Contact Name')); /** * If you are using the sample template, this array tells the template fields to render * for the search form. */ $form->assign('elements', array('contact_type', 'activity_subject', 'activity_type_id', 'activity_status_id', 'start_date', 'end_date', 'sort_name')); }
/** * Retrieve the first non-generic contact type * * @param int $id id of uf_group * @return string contact type */ static function getContactType($id) { $valid = array_filter(array_keys(CRM_Core_SelectValues::contactType())); $types = explode(',', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $id, 'group_type')); foreach ($types as $type) { if (in_array($type, $valid)) { return $type; } } }
function buildForm(&$form) { $form->add('select', 'contact_type', ts('Find...'), CRM_Core_SelectValues::contactType()); // add select for groups $group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant::group(); $form->addElement('select', 'group', ts('in'), $group); // add select for categories $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::tag(); $form->addElement('select', 'tag', ts('Tagged'), $tag); // text for sort_name $form->add('text', 'sort_name', ts('Name')); $form->assign('elements', array('sort_name', 'contact_type', 'group', 'tag')); }
/** * Retrieve the first non-generic contact type * * @param int $id * Id of uf_group. * * @return string * contact type */ public static function getContactType($id) { $validTypes = array_filter(array_keys(CRM_Core_SelectValues::contactType())); $validSubTypes = CRM_Contact_BAO_ContactType::subTypeInfo(); $typesParts = explode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $id, 'group_type')); $types = explode(',', $typesParts[0]); $cType = NULL; foreach ($types as $type) { if (in_array($type, $validTypes)) { $cType = $type; } elseif (array_key_exists($type, $validSubTypes)) { $cType = CRM_Utils_Array::value('parent', $validSubTypes[$type]); } if ($cType) { break; } } return $cType; }
/** * Retrieve the first non-generic contact type * * @param int $id id of uf_group * @return string contact type */ static function getContactType($id) { require_once 'CRM/Contact/BAO/ContactType.php'; $validTypes = array_filter(array_keys(CRM_Core_SelectValues::contactType())); $validSubTypes = CRM_Contact_BAO_ContactType::subTypeInfo(); $types = explode(',', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $id, 'group_type')); $cType = null; foreach ($types as $type) { if (in_array($type, $validTypes)) { $cType = $type; } else { if (array_key_exists($type, $validSubTypes)) { $cType = CRM_Utils_Array::value('parent', $validSubTypes[$type]); } } if ($cType) { break; } } return $cType; }
/** * Function to build the form * * @return None * @access public */ function buildQuickForm() { parent::buildQuickForm(); if ($this->_action & CRM_CORE_ACTION_DELETE) { return; } $this->applyFilter('__ALL__', 'trim'); $this->add('text', 'name_a_b', ts('Relationship Label-A to B'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_RelationshipType', 'name_a_b')); $this->addRule('name_a_b', ts('Please enter a valid Relationship Label for A to B.'), 'required'); $this->addRule('name_a_b', ts('Name already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_RelationshipType', $this->_id, 'name_a_b')); $this->add('text', 'name_b_a', ts('Relationship Label-B to A'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_RelationshipType', 'name_b_a')); $this->addRule('name_b_a', ts('Name already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_RelationshipType', $this->_id, 'name_b_a')); // add select for contact type $this->add('select', 'contact_type_a', ts('Contact Type A') . ' ', CRM_Core_SelectValues::contactType()); $this->add('select', 'contact_type_b', ts('Contact Type B') . ' ', CRM_Core_SelectValues::contactType()); $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_RelationshipType', 'description')); $this->add('checkbox', 'is_active', ts('Enabled?')); if ($this->_action & CRM_CORE_ACTION_VIEW) { $this->freeze(); $this->addElement('button', 'done', ts('Done'), array('onClick' => "location.href='civicrm/admin/reltype?reset=1&action=browse'")); } }
/** * Function to actually build the form * * @return void * @access public */ function buildQuickForm() { if ($this->_action & CRM_CORE_ACTION_DELETE) { $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Profile Field'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if (isset($this->_id)) { $params = array('id' => $this->_id); CRM_Core_BAO_UFField::retrieve($params, $defaults); $defaults['field_name'] = array($defaults['field_type'], $defaults['field_name'], $defaults['location_type_id'], $defaults['phone_type']); $this->_gid = $defaults['uf_group_id']; } else { $defaults['is_active'] = 1; } if ($this->_action & CRM_CORE_ACTION_ADD) { $uf =& new CRM_Core_DAO(); $sql = "SELECT weight FROM civicrm_uf_field WHERE uf_group_id = " . $this->_gid . " ORDER BY weight DESC LIMIT 0, 1"; $uf->query($sql); while ($uf->fetch()) { $defaults['weight'] = $uf->weight + 1; } if (empty($defaults['weight'])) { $defaults['weight'] = 1; } } // lets trim all the whitespace $this->applyFilter('__ALL__', 'trim'); //hidden field to catch the group id in profile $this->add('hidden', 'group_id', $this->_gid); //hidden field to catch the field id in profile $this->add('hidden', 'field_id', $this->_id); $fields = array(); $fields['Individual'] =& CRM_Contact_BAO_Contact::exportableFields('Individual'); $fields['Household'] =& CRM_Contact_BAO_Contact::exportableFields('Household'); $fields['Organization'] =& CRM_Contact_BAO_Contact::exportableFields('Organization'); $contribFields =& CRM_Contribute_BAO_Contribution::getContributionFields(); if (!empty($contribFields)) { $fields['Contribution'] =& $contribFields; } foreach ($fields as $key => $value) { foreach ($value as $key1 => $value1) { $this->_mapperFields[$key][$key1] = $value1['title']; $hasLocationTypes[$key][$key1] = $value1['hasLocationType']; } } require_once 'CRM/Core/BAO/LocationType.php'; $this->_location_types =& CRM_Core_PseudoConstant::locationType(); $defaultLocationType =& CRM_Core_BAO_LocationType::getDefault(); /* FIXME: dirty hack to make the default option show up first. This * avoids a mozilla browser bug with defaults on dynamically constructed * selector widgets. */ if ($defaultLocationType) { $defaultLocation = $this->_location_types[$defaultLocationType->id]; unset($this->_location_types[$defaultLocationType->id]); $this->_location_types = array($defaultLocationType->id => $defaultLocation) + $this->_location_types; } $sel1 = array('' => '-select-') + CRM_Core_SelectValues::contactType(); if (!empty($contribFields)) { $sel1['Contribution'] = 'Contributions'; } foreach ($sel1 as $key => $sel) { if ($key) { $sel2[$key] = $this->_mapperFields[$key]; } } $sel3[''] = null; $phoneTypes = CRM_Core_SelectValues::phoneType(); foreach ($sel1 as $k => $sel) { if ($k) { foreach ($this->_location_types as $key => $value) { $sel4[$k]['phone'][$key] =& $phoneTypes; } } } foreach ($sel1 as $k => $sel) { if ($k) { foreach ($this->_mapperFields[$k] as $key => $value) { if ($hasLocationTypes[$k][$key]) { $sel3[$k][$key] = $this->_location_types; } else { $sel3[$key] = null; } } } } $this->_defaults = array(); $js = "<script type='text/javascript'>\n"; $formName = "document.{$this->_name}"; $sel =& $this->addElement('hierselect', "field_name", ts('Field Name'), 'onclick="showLabel();"'); $formValues = array(); //$formValues = $this->controller->exportValues( $this->_name ); $formValues = $_POST; // using $_POST since export values don't give values on first submit if (empty($formValues)) { for ($k = 1; $k < 4; $k++) { if (!$defaults['field_name'][$k]) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } } } else { foreach ($formValues['field_name'] as $value) { for ($k = 1; $k < 4; $k++) { if (!$formValues['field_name'][$k]) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } } } } $sel->setOptions(array($sel1, $sel2, $sel3, $sel4)); $js .= "</script>\n"; $this->assign('initHideBoxes', $js); $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::ufVisibility(), true); // should the field appear in selector? $this->add('checkbox', 'in_selector', ts('In Selector?')); // weight $this->add('text', 'weight', ts('Weight'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'weight'), true); $this->addRule('weight', ts(' is a numeric field'), 'numeric'); $this->add('textarea', 'help_post', ts('Field Help'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'help_post')); // listings title $this->add('text', 'listings_title', ts('Listings Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'listings_title')); $this->addRule('listings_title', ts('Please enter a valid title for this field when displayed in user listings.'), 'title'); $this->add('checkbox', 'is_required', ts('Required?')); $this->add('checkbox', 'is_active', ts('Active?')); $this->add('checkbox', 'is_searchable', ts('Searchable?')); $this->add('checkbox', 'is_view', ts('View Only?')); // $this->add( 'checkbox', 'is_registration', ts( 'Display in Registration Form?' ) ); //$this->add( 'checkbox', 'is_match' , ts( 'Key to Match Contacts?' ) ); $this->add('text', 'label', ts('Field Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'label')); // add buttons $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); $this->addFormRule(array('CRM_UF_Form_Field', 'formRule')); // if view mode pls freeze it with the done button. if ($this->_action & CRM_CORE_ACTION_VIEW) { $this->freeze(); $this->addElement('button', 'done', ts('Done'), array('onClick' => "location.href='civicrm/admin/uf/group/field?reset=1&action=browse&gid=" . $this->_gid . "'")); } $this->setDefaults($defaults); }
/** * Build the form * * @access public * @return void */ function buildQuickForm() { $this->add('select', 'contact_type', ts('Find...'), CRM_Core_SelectValues::contactType()); // add select for groups $group = array('' => ts('- any group -')) + $this->_group; $this->_groupElement =& $this->addElement('select', 'group', ts('in'), $group); // add select for categories $tag = array('' => ts('- any tag -')) + $this->_tag; $this->_tagElement =& $this->addElement('select', 'tag', ts('Tagged'), $tag); // text for sort_name $this->add('text', 'sort_name', ts('Name or email')); //commented ajax autocomplete // $this->add('text', 'sort_name', ts('Name or email'), 'onkeyup="getSearchResult(this,event, false);" onblur="getSearchResult(this,event, false);" autocomplete="off"' ); $this->buildQuickFormCommon(); }
/** * handle the values in import mode * * @param int $onDuplicate the code for what action to take on duplicates * @param array $values the array of values belonging to this line * * @return boolean the result of this processing * @access public */ function import($onDuplicate, &$values) { // first make sure this is a valid line //$this->_updateWithId = false; $response = $this->summary($values); if ($response != CRM_IMPORT_PARSER_VALID) { return $response; } $params =& $this->getActiveFieldParams(); $formatted = array('contact_type' => $this->_contactType); //for date-Formats $session =& CRM_Core_Session::singleton(); $dateType = $session->get("dateType"); $customFields = CRM_Core_BAO_CustomField::getFields($params['contact_type']); foreach ($params as $key => $val) { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) { if ($customFields[$customFieldID][2] == 'Date') { CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key); } } if ($key == 'birth_date') { if ($val) { CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key); } } } //date-Format part ends if ($GLOBALS['_CRM_IMPORT_PARSER_CONTACT']['indieFields'] == null) { require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_DAO_" . $this->_contactType) . ".php"; eval('$tempIndieFields =& CRM_Contact_DAO_' . $this->_contactType . '::import();'); //modified for PHP4 issue $GLOBALS['_CRM_IMPORT_PARSER_CONTACT']['indieFields'] = $tempIndieFields; } foreach ($params as $key => $field) { if ($field == null || $field === '') { continue; } if (is_array($field)) { foreach ($field as $value) { $break = false; if (is_array($value)) { foreach ($value as $name => $testForEmpty) { if ($name !== 'phone_type' && ($testForEmpty === '' || $testForEmpty == null)) { $break = true; break; } } } else { $break = true; } if (!$break) { _crm_add_formatted_param($value, $formatted); } } continue; } $value = array($key => $field); if (array_key_exists($key, $GLOBALS['_CRM_IMPORT_PARSER_CONTACT']['indieFields'])) { $value['contact_type'] = $this->_contactType; } _crm_add_formatted_param($value, $formatted); } /*if (in_array('id',$this->_mapperKeys)) { $this->_updateWithId = true; }*/ $relationship = false; // Support Match and Update Via Contact ID if ($this->_updateWithId) { $error = _crm_duplicate_formatted_contact($formatted); if (CRM_Import_Parser_Contact::isDuplicate($error)) { $matchedIDs = explode(',', $error->_errors[0]['params'][0]); if (count($matchedIDs) >= 1) { $updateflag = true; foreach ($matchedIDs as $contactId) { if ($params['id'] == $contactId) { $paramsValues = array('contact_id' => $contactId); $contactExits = crm_get_contact($paramsValues); if ($formatted['contact_type'] == $contactExits->contact_type) { $newContact = crm_update_contact_formatted($contactId, $formatted, true); $updateflag = false; $this->_retCode = CRM_IMPORT_PARSER_VALID; } else { $message = "Mismatched contact Types :"; array_unshift($values, $message); $updateflag = false; $this->_retCode = CRM_IMPORT_PARSER_NO_MATCH; } } } if ($updateflag) { $message = "Mismatched contact IDs OR Mismatched contact Types :"; array_unshift($values, $message); $this->_retCode = CRM_IMPORT_PARSER_NO_MATCH; } } } else { $paramsValues = array('contact_id' => $params['id']); $contact = crm_get_contact($paramsValues); if (is_a($contact, CRM_Contact_BAO_Contact)) { if ($formatted['contact_type'] == $contact->contact_type) { $newContact = crm_update_contact_formatted($contact->id, $formatted, true); $this->_retCode = CRM_IMPORT_PARSER_VALID; } else { $message = "Mismatched contact Types :"; array_unshift($values, $message); $this->_retCode = CRM_IMPORT_PARSER_NO_MATCH; } } else { $message = "No contact found for this contact ID:" . $params['id']; array_unshift($values, $message); $this->_retCode = CRM_IMPORT_PARSER_NO_MATCH; } } if (is_a($newContact, CRM_Contact_BAO_Contact)) { $relationship = true; } else { if (is_a($error, CRM_Core_Error)) { $newContact = $error; $relationship = true; } } if ($newContact && !is_a($newContact, CRM_Core_Error)) { $this->_newContacts[] = $newContact->id; } } else { $newContact = crm_create_contact_formatted($formatted, $onDuplicate); $relationship = true; } if ($relationship) { if (CRM_Import_Parser_Contact::isDuplicate($newContact)) { foreach ($newContact->_errors[0]['params'] as $cid) { $primaryContactId = $cid; } } else { $primaryContactId = $newContact->id; } if (CRM_Import_Parser_Contact::isDuplicate($newContact) || is_a($newContact, CRM_Contact_BAO_Contact)) { //relationship contact insert foreach ($params as $key => $field) { list($id, $first, $second) = explode('_', $key); if (!($first == 'a' && $second == 'b') && !($first == 'b' && $second == 'a')) { continue; } $relationType = new CRM_Contact_DAO_RelationshipType(); $relationType->id = $id; $relationType->find(true); $name_a_b = $relationType->name_a_b; if ($params[$key]['contact_type']) { $formatting = array('contact_type' => $params[$key]['contact_type']); } else { $fld = array_keys($params[$key]); foreach (CRM_Core_SelectValues::contactType() as $cType => $val) { if ($cType) { $contactFields =& CRM_Contact_BAO_Contact::importableFields($cType); if (array_key_exists($fld[0], $contactFields)) { $formatting['contact_type'] = $cType; $params[$key]['contact_type'] = $cType; $field['contact_type'] = $cType; break; } } } } $contactFields = null; if ($contactFields == null) { require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_DAO_" . $params[$key]['contact_type']) . ".php"; eval('$contactFields =& CRM_Contact_DAO_' . $params[$key]['contact_type'] . '::import();'); } foreach ($field as $k => $v) { if ($v == null || $v === '') { continue; } if (is_array($v)) { foreach ($v as $value) { $break = false; foreach ($value as $testForEmpty) { if ($testForEmpty === '' || $testForEmpty == null) { $break = true; break; } } if (!$break) { _crm_add_formatted_param($value, $formatting); } } continue; } $value = array($k => $v); if (array_key_exists($k, $contactFields)) { $value['contact_type'] = $params[$key]['contact_type']; } _crm_add_formatted_param($value, $formatting); } $relatedNewContact = crm_create_contact_formatted($formatting, $onDuplicate); if (CRM_Import_Parser_Contact::isDuplicate($relatedNewContact)) { foreach ($relatedNewContact->_errors[0]['params'] as $cid) { $relContactId = $cid; } } else { $relContactId = $relatedNewContact->id; $this->_newRelatedContacts[] = $relContactId; } if (CRM_Import_Parser_Contact::isDuplicate($relatedNewContact) || is_a($relatedNewContact, CRM_Contact_BAO_Contact)) { //store the related contact id for groups //$this->_newRelatedContacts[] = $relContactId; // now create the relationship record $relationParams = array(); $relationParams = array('relationship_type_id' => $key, 'contact_check' => array($relContactId => 1)); $relationIds = array('contact' => $primaryContactId); CRM_Contact_BAO_Relationship::create($relationParams, $relationIds); //check if the two contacts are related and of type individual if ($params[$key]['contact_type'] == 'Individual' && $this->_contactType == 'Individual') { if ($name_a_b == 'Spouse of' || $name_a_b == 'Child of' || $name_a_b == 'Sibling of') { $householdName = "The " . $formatting['last_name'] . " household"; $householdFormatting = array('contact_type' => 'Household', 'household_name' => $householdName); $householdContact = crm_create_contact_formatted($householdFormatting, $onDuplicate); if (CRM_Import_Parser_Contact::isDuplicate($householdContact)) { foreach ($householdContact->_errors[0]['params'] as $cid) { $householdId = $cid; } } else { $householdId = $householdContact->id; $this->_newRelatedContacts[] = $householdId; } //Household contact is created //for two related individual contacts waiting confirmation whether //to add it in a group //$this->_newRelatedContacts[] = $householdId; $relationParams = array(); // adding household relationship $relType = '7_' . $second . '_' . $first; $relationParams = array('relationship_type_id' => $relType, 'contact_check' => array($relContactId => 1, $primaryContactId => 1)); $relationIds = array('contact' => $householdId); CRM_Contact_BAO_Relationship::create($relationParams, $relationIds); } } } } } } if ($this->_updateWithId) { return $this->_retCode; } //dupe checking if (is_a($newContact, CRM_Core_Error)) { $code = $newContact->_errors[0]['code']; if ($code == CRM_CORE_ERROR_DUPLICATE_CONTACT) { $urls = array(); foreach ($newContact->_errors[0]['params'] as $cid) { $urls[] = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $cid, true); } $url_string = implode("\n", $urls); array_unshift($values, $url_string); /* If we duplicate more than one record, skip no matter what */ if (count($newContact->_errors[0]['params']) > 1) { array_unshift($values, ts('Record duplicates multiple contacts')); return CRM_IMPORT_PARSER_ERROR; } /* Params only had one id, so shift it out */ $contactId = array_shift($newContact->_errors[0]['params']); if ($onDuplicate == CRM_IMPORT_PARSER_DUPLICATE_REPLACE) { $newContact = crm_replace_contact_formatted($contactId, $formatted); } else { if ($onDuplicate == CRM_IMPORT_PARSER_DUPLICATE_UPDATE) { $newContact = crm_update_contact_formatted($contactId, $formatted, true); } else { if ($onDuplicate == CRM_IMPORT_PARSER_DUPLICATE_FILL) { $newContact = crm_update_contact_formatted($contactId, $formatted, false); } } } // else skip does nothing and just returns an error code. if ($newContact && !is_a($newContact, CRM_Core_Error)) { $this->_newContacts[] = $newContact->id; } //CRM-262 No Duplicate Checking if ($onDuplicate == CRM_IMPORT_PARSER_DUPLICATE_SKIP) { return CRM_IMPORT_PARSER_DUPLICATE; } return CRM_IMPORT_PARSER_VALID; } else { /* Not a dupe, so we had an error */ array_unshift($values, $newContact->_errors[0]['message']); return CRM_IMPORT_PARSER_ERROR; } } if ($newContact && !is_a($newContact, CRM_Core_Error)) { $this->_newContacts[] = $newContact->id; } return CRM_IMPORT_PARSER_VALID; }
/** * Function to actually build the form * * @return void * @access public */ public function buildQuickForm() { if ($this->_action & CRM_Core_Action::DELETE) { $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Profile Field'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if (isset($this->_id)) { $params = array('id' => $this->_id); CRM_Core_BAO_UFField::retrieve($params, $defaults); // set it to null if so (avoids crappy E_NOTICE errors below $defaults['location_type_id'] = CRM_Utils_Array::value('location_type_id', $defaults); $specialFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'geo_code_1', 'geo_code_2', 'state_province', 'country', 'county', 'phone', 'email', 'im', 'address_name'); if (!$defaults['location_type_id'] && in_array($defaults['field_name'], $specialFields)) { $defaults['location_type_id'] = 0; } $defaults['field_name'] = array($defaults['field_type'], $defaults['field_name'], $defaults['location_type_id'], CRM_Utils_Array::value('phone_type_id', $defaults)); $this->_gid = $defaults['uf_group_id']; } else { $defaults['is_active'] = 1; } if ($this->_action & CRM_Core_Action::ADD) { $fieldValues = array('uf_group_id' => $this->_gid); $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_UFField', $fieldValues); } // lets trim all the whitespace $this->applyFilter('__ALL__', 'trim'); //hidden field to catch the group id in profile $this->add('hidden', 'group_id', $this->_gid); //hidden field to catch the field id in profile $this->add('hidden', 'field_id', $this->_id); $fields = array(); $fields['Individual'] =& CRM_Contact_BAO_Contact::importableFields('Individual', false, false, true); $fields['Household'] =& CRM_Contact_BAO_Contact::importableFields('Household', false, false, true); $fields['Organization'] =& CRM_Contact_BAO_Contact::importableFields('Organization', false, false, true); // add current employer for individuals $fields['Individual']['current_employer'] = array('name' => 'organization_name', 'title' => ts('Current Employer')); // unset unwanted fields $unsetFieldArray = array('note', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'id'); foreach ($unsetFieldArray as $value) { unset($fields['Individual'][$value]); unset($fields['Household'][$value]); unset($fields['Organization'][$value]); } require_once 'CRM/Core/BAO/Preferences.php'; $addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true); if (!$addressOptions['county']) { unset($fields['Individual']['county']); unset($fields['Household']['county']); unset($fields['Organization']['county']); } //build the common contact fields array CRM-3037. foreach ($fields['Individual'] as $key => $value) { if (CRM_Utils_Array::value($key, $fields['Household']) && CRM_Utils_Array::value($key, $fields['Organization'])) { $fields['Contact'][$key] = $value; //as we move common fields to contacts. There fore these fields //are unset from resoective array's. unset($fields['Individual'][$key]); unset($fields['Household'][$key]); unset($fields['Organization'][$key]); } } // add current employer for individuals $fields['Contact']['id'] = array('name' => 'id', 'title' => ts('Internal Contact ID')); unset($fields['Contact']['contact_type']); // Contact Sub Types For Profile $contactSubTypes = array(); $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo(); foreach ($subTypes as $name => $val) { //custom fields for sub type $subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($name); if (!empty($subTypeFields)) { if (array_key_exists($val['parent'], $fields)) { $fields[$name] = $fields[$val['parent']] + $subTypeFields; } else { $fields[$name] = $subTypeFields; } $contactSubTypes[$name] = $val['label']; } } unset($subTypes); if (CRM_Core_Permission::access('Quest')) { require_once 'CRM/Quest/BAO/Student.php'; $fields['Student'] =& CRM_Quest_BAO_Student::exportableFields(); } if (CRM_Core_Permission::access('CiviContribute')) { $contribFields =& CRM_Contribute_BAO_Contribution::getContributionFields(); if (!empty($contribFields)) { unset($contribFields['is_test']); unset($contribFields['is_pay_later']); unset($contribFields['contribution_id']); $fields['Contribution'] =& $contribFields; } } if (CRM_Core_Permission::access('CiviEvent')) { require_once 'CRM/Event/BAO/Query.php'; $participantFields =& CRM_Event_BAO_Query::getParticipantFields(true); if (!empty($participantFields)) { unset($participantFields['external_identifier']); unset($participantFields['event_id']); unset($participantFields['participant_contact_id']); unset($participantFields['participant_is_test']); unset($participantFields['participant_fee_level']); unset($participantFields['participant_id']); unset($participantFields['participant_is_pay_later']); $fields['Participant'] =& $participantFields; } } if (CRM_Core_Permission::access('CiviMember')) { require_once 'CRM/Member/BAO/Membership.php'; $membershipFields =& CRM_Member_BAO_Membership::getMembershipFields(); unset($membershipFields['membership_id']); unset($membershipFields['join_date']); unset($membershipFields['membership_start_date']); unset($membershipFields['membership_type_id']); unset($membershipFields['membership_end_date']); unset($membershipFields['member_is_test']); unset($membershipFields['is_override']); unset($membershipFields['status_id']); unset($membershipFields['member_is_pay_later']); $fields['Membership'] =& $membershipFields; } $noSearchable = array(); foreach ($fields as $key => $value) { foreach ($value as $key1 => $value1) { //CRM-2676, replacing the conflict for same custom field name from different custom group. require_once 'CRM/Core/BAO/CustomField.php'; if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key1)) { $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $customFieldId, 'custom_group_id'); $customGroupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'title'); $this->_mapperFields[$key][$key1] = $value1['title'] . ' :: ' . $customGroupName; } else { $this->_mapperFields[$key][$key1] = $value1['title']; } $hasLocationTypes[$key][$key1] = CRM_Utils_Array::value('hasLocationType', $value1); // hide the 'is searchable' field for 'File' custom data if (isset($value1['data_type']) && isset($value1['html_type']) && ($value1['data_type'] == 'File' && $value1['html_type'] == 'File' || $value1['data_type'] == 'Link' && $value1['html_type'] == 'Link')) { if (!in_array($value1['title'], $noSearchable)) { $noSearchable[] = $value1['title']; } } } } $this->assign('noSearchable', $noSearchable); require_once 'CRM/Core/BAO/LocationType.php'; $this->_location_types =& CRM_Core_PseudoConstant::locationType(); $defaultLocationType =& CRM_Core_BAO_LocationType::getDefault(); /* FIXME: dirty hack to make the default option show up first. This * avoids a mozilla browser bug with defaults on dynamically constructed * selector widgets. */ if ($defaultLocationType) { $defaultLocation = $this->_location_types[$defaultLocationType->id]; unset($this->_location_types[$defaultLocationType->id]); $this->_location_types = array($defaultLocationType->id => $defaultLocation) + $this->_location_types; } $this->_location_types = array('Primary') + $this->_location_types; $sel1 = array('' => '- select -') + array('Contact' => 'Contacts') + CRM_Core_SelectValues::contactType() + $contactSubTypes; if (CRM_Core_Permission::access('Quest')) { $sel1['Student'] = 'Students'; } if (CRM_Core_Permission::access('CiviEvent')) { $sel1['Participant'] = 'Participants'; } if (!empty($contribFields)) { $sel1['Contribution'] = 'Contributions'; } if (!empty($membershipFields)) { $sel1['Membership'] = 'Membership'; } foreach ($sel1 as $key => $sel) { if ($key) { $sel2[$key] = $this->_mapperFields[$key]; } } $sel3[''] = null; $phoneTypes = CRM_Core_PseudoConstant::phoneType(); ksort($phoneTypes); foreach ($sel1 as $k => $sel) { if ($k) { foreach ($this->_location_types as $key => $value) { $sel4[$k]['phone'][$key] =& $phoneTypes; } } } foreach ($sel1 as $k => $sel) { if ($k) { if (is_array($this->_mapperFields[$k])) { foreach ($this->_mapperFields[$k] as $key => $value) { if ($hasLocationTypes[$k][$key]) { $sel3[$k][$key] = $this->_location_types; } else { $sel3[$key] = null; } } } } } $this->_defaults = array(); $js = "<script type='text/javascript'>\n"; $formName = "document.{$this->_name}"; $alreadyMixProfile = false; if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) { $alreadyMixProfile = true; } $this->assign('alreadyMixProfile', $alreadyMixProfile); $attributes = array('onclick' => "showLabel();mixProfile();", 'onblur' => 'mixProfile();'); $sel =& $this->addElement('hierselect', "field_name", ts('Field Name'), $attributes); $formValues = array(); $formValues = $this->exportValues(); if (empty($formValues)) { for ($k = 1; $k < 4; $k++) { if (!$defaults['field_name'][$k]) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } } } else { if (!empty($formValues['field_name'])) { foreach ($formValues['field_name'] as $value) { for ($k = 1; $k < 4; $k++) { if (!isset($formValues['field_name'][$k]) || !$formValues['field_name'][$k]) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } else { $js .= "{$formName}['field_name[{$k}]'].style.display = '';\n"; } } } } else { for ($k = 1; $k < 4; $k++) { if (!isset($defaults['field_name'][$k])) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } } } } foreach ($sel2 as $k => $v) { if (is_array($sel2[$k])) { asort($sel2[$k]); } } $sel->setOptions(array($sel1, $sel2, $sel3, $sel4)); $js .= "</script>\n"; $this->assign('initHideBoxes', $js); $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::ufVisibility(), true, array("onChange" => "showHideSeletorSearch(this.value);")); //CRM-4363 $js = array('onclick' => "mixProfile();"); // should the field appear in selectors (as a column)? $this->add('checkbox', 'in_selector', ts('Results Column?'), null, null, $js); $this->add('checkbox', 'is_searchable', ts('Searchable?'), null, null, $js); // weight $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'weight'), true); $this->addRule('weight', ts('is a numeric field'), 'numeric'); $this->add('textarea', 'help_post', ts('Field Help'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'help_post')); // listings title $this->add('text', 'listings_title', ts('Listings Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'listings_title')); $this->addRule('listings_title', ts('Please enter a valid title for this field when displayed in user listings.'), 'title'); $this->add('checkbox', 'is_required', ts('Required?')); $this->add('checkbox', 'is_active', ts('Active?')); $this->add('checkbox', 'is_view', ts('View Only?')); // $this->add( 'checkbox', 'is_registration', ts( 'Display in Registration Form?' ) ); //$this->add( 'checkbox', 'is_match' , ts( 'Key to Match Contacts?' ) ); $this->add('text', 'label', ts('Field Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'label')); $js = null; if ($this->_hasSearchableORInSelector) { $js = array('onclick' => "return verify( );"); } // add buttons $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => true, 'js' => $js), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $js), array('type' => 'cancel', 'name' => ts('Cancel')))); $this->addFormRule(array('CRM_UF_Form_Field', 'formRule'), $this); // if view mode pls freeze it with the done button. if ($this->_action & CRM_Core_Action::VIEW) { $this->freeze(); $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/uf/group/field?reset=1&action=browse&gid=" . $this->_gid . "'")); } $this->setDefaults($defaults); }
/** * Build the form * * @access public * @return void */ function buildQuickForm() { // add checkboxes for contact type $contact_type = array(); foreach (CRM_Core_SelectValues::contactType() as $k => $v) { if (!empty($k)) { $contact_type[] = HTML_QuickForm::createElement('checkbox', $k, null, $v); } } $this->addGroup($contact_type, 'contact_type', ts('Contact Type(s)'), '<br />'); // checkboxes for groups $group = array(); foreach ($this->_group as $groupID => $groupName) { $this->_groupElement =& $this->addElement('checkbox', "group[{$groupID}]", null, $groupName); } // checkboxes for categories foreach ($this->_tag as $tagID => $tagName) { $this->_tagElement =& $this->addElement('checkbox', "tag[{$tagID}]", null, $tagName); } // add text box for last name, first name, street name, city $this->addElement('text', 'sort_name', ts('Find...'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); $this->addElement('text', 'street_address', ts('Street Address'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address', 'street_address')); $this->addElement('text', 'city', ts('City'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address', 'city')); // select for state province $stateProvince = array('' => ts('- any state/province -')) + CRM_Core_PseudoConstant::stateProvince(); $this->addElement('select', 'state_province', ts('State/Province'), $stateProvince); // select for country $country = array('' => ts('- any country -')) + CRM_Core_PseudoConstant::country(); $this->addElement('select', 'country', ts('Country'), $country); // add text box for postal code $this->addElement('text', 'postal_code', ts('Postal Code'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address', 'postal_code')); $this->addElement('text', 'postal_code_low', ts('Range-From'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address', 'postal_code')); $this->addElement('text', 'postal_code_high', ts('To'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address', 'postal_code')); $this->addElement('text', 'location_name', ts('Location Name'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Location', 'name')); // checkboxes for DO NOT phone, email, mail // we take labels from SelectValues $t = CRM_Core_SelectValues::privacy(); $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_phone', null, $t['do_not_phone']); $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_email', null, $t['do_not_email']); $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_mail', null, $t['do_not_mail']); $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_trade', null, $t['do_not_trade']); $this->addGroup($privacy, 'privacy', ts('Privacy'), ' '); // checkboxes for location type $location_type = array(); $locationType = CRM_Core_PseudoConstant::locationType(); foreach ($locationType as $locationTypeID => $locationTypeName) { $location_type[] = HTML_QuickForm::createElement('checkbox', $locationTypeID, null, $locationTypeName); } $this->addGroup($location_type, 'location_type', ts('Location Types'), ' '); // textbox for Activity Type $this->addElement('text', 'activity_type', ts('Activity Type'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_ActivityHistory', 'activity_type')); // Date selects for activity date $this->add('date', 'activity_date_from', ts('Activity Dates - From'), CRM_Core_SelectValues::date('relative')); $this->addRule('activity_date_from', ts('Select a valid date.'), 'qfDate'); $this->add('date', 'activity_date_to', ts('To'), CRM_Core_SelectValues::date('relative')); $this->addRule('activity_date_to', ts('Select a valid date.'), 'qfDate'); $this->assign('validCiviContribute', false); if (CRM_Utils_System::accessCiviContribute()) { $this->assign('validCiviContribute', true); require_once 'CRM/Contribute/Form/Search.php'; CRM_Contribute_Form_Search::buildQuickFormCommon($this); } //Custom data Search Fields $this->customDataSearch(); $this->buildQuickFormCommon(); }
/** * Function to build the mapping form * * @params object $form form object * @params string $mappingType mapping type (Export/Import/Search Builder) * @params int $mappingId mapping id * @params mixed $columnCount column count is int for and array for search builder * @params int $blockCount block count (no of blocks shown) * * @return none * @access public * @static */ static function buildMappingForm(&$form, $mappingType = 'Export', $mappingId = null, $columnNo, $blockCount = 3, $exportMode = null) { if ($mappingType == 'Export') { $name = "Map"; $columnCount = array('1' => $columnNo); } else { if ($mappingType == 'Search Builder') { $name = "Builder"; $columnCount = $columnNo; } } //get the saved mapping details require_once 'CRM/Core/DAO/Mapping.php'; require_once 'CRM/Contact/BAO/Contact.php'; require_once 'CRM/Core/BAO/LocationType.php'; if ($mappingType == 'Export') { $form->applyFilter('saveMappingName', 'trim'); //to save the current mappings if (!isset($mappingId)) { $saveDetailsName = ts('Save this field mapping'); $form->add('text', 'saveMappingName', ts('Name')); $form->add('text', 'saveMappingDesc', ts('Description')); } else { $form->assign('loadedMapping', $mappingId); $params = array('id' => $mappingId); $temp = array(); $mappingDetails = CRM_Core_BAO_Mapping::retrieve($params, $temp); $form->assign('savedName', $mappingDetails->name); $form->add('hidden', 'mappingId', $mappingId); $form->addElement('checkbox', 'updateMapping', ts('Update this field mapping'), null); $saveDetailsName = ts('Save as a new field mapping'); $form->add('text', 'saveMappingName', ts('Name')); $form->add('text', 'saveMappingDesc', ts('Description')); } $form->addElement('checkbox', 'saveMapping', $saveDetailsName, null, array('onclick' => "showSaveDetails(this)")); $form->addFormRule(array('CRM_Export_Form_Map', 'formRule'), $form->get('mappingTypeId')); } else { if ($mappingType == 'Search Builder') { $form->addElement('submit', 'addBlock', ts('Also include contacts where'), array('class' => 'submit-link')); } } $defaults = array(); $hasLocationTypes = array(); $hasRelationTypes = array(); $fields = array(); if ($mappingType == 'Export') { $required = true; } else { if ($mappingType == 'Search Builder') { $required = false; } } $contactType = array('Individual', 'Household', 'Organization'); foreach ($contactType as $value) { $relationfields[$value] = $fields[$value] =& CRM_Contact_BAO_Contact::exportableFields($value, false, $required); if ($mappingType == 'Export') { $relationships = array(); $relationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, null, null, $value); asort($relationshipTypes); foreach ($relationshipTypes as $key => $var) { list($type) = explode('_', $key); $relationships[$key]['title'] = $var; $relationships[$key]['headerPattern'] = '/' . preg_quote($var, '/') . '/'; $relationships[$key]['export'] = true; $relationships[$key]['relationship_type_id'] = $type; $relationships[$key]['related'] = true; $relationships[$key]['hasRelationType'] = 1; } if (!empty($relationships)) { $fields[$value] = array_merge($fields[$value], array('related' => array('title' => ts('- related contact info -'))), $relationships); } } } //get the current employer for mapping. if ($required) { $fields['Individual']['current_employer']['title'] = ts('Current Employer'); } // add component fields $compArray = array(); if (CRM_Core_Permission::access('Quest')) { require_once 'CRM/Quest/BAO/Student.php'; $fields['Student'] =& CRM_Quest_BAO_Student::exportableFields(); $compArray['Student'] = 'Student'; } //we need to unset groups, tags, notes for component export require_once 'CRM/Export/Form/Select.php'; if ($exportMode != CRM_Export_Form_Select::CONTACT_EXPORT) { foreach (array('groups', 'tags', 'notes') as $value) { unset($fields['Individual'][$value]); unset($fields['Household'][$value]); unset($fields['Organization'][$value]); } } if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::CONTRIBUTE_EXPORT) { if (CRM_Core_Permission::access('CiviContribute')) { require_once 'CRM/Contribute/BAO/Contribution.php'; $fields['Contribution'] =& CRM_Contribute_BAO_Contribution::exportableFields(); unset($fields['Contribution']['contribution_contact_id']); $compArray['Contribution'] = ts('Contribution'); } } if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::EVENT_EXPORT) { if (CRM_Core_Permission::access('CiviEvent')) { require_once 'CRM/Event/BAO/Participant.php'; $fields['Participant'] =& CRM_Event_BAO_Participant::exportableFields(); unset($fields['Participant']['participant_contact_id']); $compArray['Participant'] = ts('Participant'); } } if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::MEMBER_EXPORT) { if (CRM_Core_Permission::access('CiviMember')) { require_once 'CRM/Member/BAO/Membership.php'; $fields['Membership'] =& CRM_Member_BAO_Membership::getMembershipFields(); unset($fields['Membership']['membership_contact_id']); $compArray['Membership'] = ts('Membership'); } } if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::PLEDGE_EXPORT) { if (CRM_Core_Permission::access('CiviPledge')) { require_once 'CRM/Pledge/BAO/Pledge.php'; $fields['Pledge'] =& CRM_Pledge_BAO_Pledge::exportableFields(); unset($fields['Pledge']['pledge_contact_id']); $compArray['Pledge'] = ts('Pledge'); } } if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::CASE_EXPORT) { if (CRM_Core_Permission::access('CiviCase')) { require_once 'CRM/Case/BAO/Case.php'; $fields['Case'] =& CRM_Case_BAO_Case::exportableFields(); $compArray['Case'] = ts('Case'); require_once 'CRM/Activity/BAO/Activity.php'; $fields['Activity'] =& CRM_Activity_BAO_Activity::exportableFields(); $compArray['Activity'] = ts('Case Activity'); unset($fields['Case']['case_contact_id']); } } //Contact Sub Type For export $contactSubTypes = array(); $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo(); foreach ($subTypes as $subType => $val) { //adding subtype specific relationships CRM-5256 $csRelationships = array(); $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, null, null, $val['parent'], false, 'label', true, $subType); foreach ($subTypeRelationshipTypes as $key => $var) { if (!array_key_exists($key, $fields[$val['parent']])) { list($type) = explode('_', $key); $csRelationships[$key]['title'] = $var; $csRelationships[$key]['headerPattern'] = '/' . preg_quote($var, '/') . '/'; $csRelationships[$key]['export'] = true; $csRelationships[$key]['relationship_type_id'] = $type; $csRelationships[$key]['related'] = true; $csRelationships[$key]['hasRelationType'] = 1; } } $fields[$subType] = $fields[$val['parent']] + $csRelationships; //custom fields for sub type $subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($subType); $fields[$subType] += $subTypeFields; if (!empty($subTypeFields) || !empty($csRelationships)) { $contactSubTypes[$subType] = $val['label']; } } unset($subTypes); foreach ($fields as $key => $value) { foreach ($value as $key1 => $value1) { //CRM-2676, replacing the conflict for same custom field name from different custom group. $customGroupName = self::getCustomGroupName($key1); if ($customGroupName) { $relatedMapperFields[$key][$key1] = $mapperFields[$key][$key1] = $customGroupName . ': ' . $value1['title']; } else { $relatedMapperFields[$key][$key1] = $mapperFields[$key][$key1] = $value1['title']; } if (isset($value1['hasLocationType'])) { $hasLocationTypes[$key][$key1] = $value1['hasLocationType']; } if (isset($value1['hasRelationType'])) { $hasRelationTypes[$key][$key1] = $value1['hasRelationType']; unset($relatedMapperFields[$key][$key1]); } } if (array_key_exists('related', $relatedMapperFields[$key])) { unset($relatedMapperFields[$key]['related']); } } $mapperKeys = array_keys($mapperFields); $locationTypes =& CRM_Core_PseudoConstant::locationType(); $defaultLocationType =& CRM_Core_BAO_LocationType::getDefault(); /* FIXME: dirty hack to make the default option show up first. This * avoids a mozilla browser bug with defaults on dynamically constructed * selector widgets. */ if ($defaultLocationType) { $defaultLocation = $locationTypes[$defaultLocationType->id]; unset($locationTypes[$defaultLocationType->id]); $locationTypes = array($defaultLocationType->id => $defaultLocation) + $locationTypes; } $locationTypes = array(' ' => ts('Primary')) + $locationTypes; $sel1 = array('' => ts('- select record type -')) + CRM_Core_SelectValues::contactType() + $compArray + $contactSubTypes; foreach ($sel1 as $key => $sel) { if ($key) { $sel2[$key] = $mapperFields[$key]; } } $sel3[''] = null; $sel5[''] = null; $phoneTypes = CRM_Core_PseudoConstant::phoneType(); $imProviders = CRM_Core_PseudoConstant::IMProvider(); asort($phoneTypes); foreach ($sel1 as $k => $sel) { if ($k) { foreach ($locationTypes as $key => $value) { if (trim($key) != '') { $sel4[$k]['phone'][$key] =& $phoneTypes; $sel4[$k]['im'][$key] =& $imProviders; } } } } foreach ($sel1 as $k => $sel) { if ($k) { foreach ($mapperFields[$k] as $key => $value) { if (isset($hasLocationTypes[$k][$key])) { $sel3[$k][$key] = $locationTypes; } else { $sel3[$key] = null; } } } } //Array for core fields and relationship custom data $relationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, null, null, null, true); if ($mappingType == 'Export') { foreach ($sel1 as $k => $sel) { if ($k) { foreach ($mapperFields[$k] as $field => $dontCare) { if (isset($hasRelationTypes[$k][$field])) { list($id, $first, $second) = explode('_', $field); $relationshipCustomFields = self::getRelationTypeCustomGroupData($id); asort($relationshipCustomFields); require_once 'CRM/Contact/BAO/RelationshipType.php'; $relationshipType =& new CRM_Contact_BAO_RelationshipType(); $relationshipType->id = $id; if ($relationshipType->find(true)) { $direction = "contact_sub_type_{$second}"; if (isset($relationshipType->{$direction})) { $relatedFields = array_merge($relatedMapperFields[$relationshipType->{$direction}], $relationshipCustomFields); } else { $target_type = 'contact_type_' . $second; $relatedFields = array_merge($relatedMapperFields[$relationshipType->{$target_type}], $relationshipCustomFields); } } $relationshipType->free(); $sel5[$k][$field] = $relatedFields; } } } } //Location Type for relationship fields foreach ($sel5 as $k => $v) { if ($v) { foreach ($v as $rel => $fields) { foreach ($fields as $field => $fieldLabel) { if (isset($hasLocationTypes[$k][$field])) { $sel6[$k][$rel][$field] = $locationTypes; } } } } } //PhoneTypes for relationship fields $sel7[''] = null; foreach ($sel6 as $k => $rel) { if ($k) { foreach ($rel as $phonekey => $phonevalue) { foreach ($locationTypes as $locType => $loc) { if (trim($locType) != '') { $sel7[$k][$phonekey]['phone'][$locType] =& $phoneTypes; $sel7[$k][$phonekey]['im'][$locType] =& $imProviders; } } } } } } //special fields that have location, hack for primary location $specialFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'geo_code_1', 'geo_code_2', 'state_province', 'country', 'phone', 'email', 'im'); $relationFields = array(); if (isset($mappingId)) { $colCnt = 0; list($mappingName, $mappingContactType, $mappingLocation, $mappingPhoneType, $mappingImProvider, $mappingRelation, $mappingOperator, $mappingValue) = CRM_Core_BAO_Mapping::getMappingFields($mappingId); $blkCnt = count($mappingName); if ($blkCnt >= $blockCount) { $blockCount = $blkCnt + 1; } for ($x = 1; $x < $blockCount; $x++) { $colCnt = count($mappingName[$x]); if ($colCnt >= $columnCount[$x]) { $columnCount[$x] = $colCnt; } } } $defaults = array(); $noneArray = array(); $nullArray = array(); //used to warn for mismatch column count or mismatch mapping $warning = 0; for ($x = 1; $x < $blockCount; $x++) { for ($i = 0; $i < $columnCount[$x]; $i++) { $sel =& $form->addElement('hierselect', "mapper[{$x}][{$i}]", ts('Mapper for Field %1', array(1 => $i)), null); $jsSet = false; if (isset($mappingId)) { $locationId = isset($mappingLocation[$x][$i]) ? $mappingLocation[$x][$i] : 0; if (isset($mappingName[$x][$i])) { if (is_array($mapperFields[$mappingContactType[$x][$i]])) { if (isset($mappingRelation[$x][$i])) { $contactDetails = strtolower(str_replace(" ", "_", $mappingName[$x][$i])); $relLocationId = isset($mappingLocation[$x][$i]) ? $mappingLocation[$x][$i] : 0; if (!$relLocationId && in_array($mappingName[$x][$i], $specialFields)) { $relLocationId = " "; } $relPhoneType = isset($mappingPhoneType[$x][$i]) ? $mappingPhoneType[$x][$i] : null; $defaults["mapper[{$x}][{$i}]"] = array($mappingContactType[$x][$i], $mappingRelation[$x][$i], $locationId, $phoneType, $mappingName[$x][$i], $relLocationId, $relPhoneType); if (!$locationId) { $noneArray[] = array($x, $i, 2); } if (!$phoneType && !$imProvider) { $noneArray[] = array($x, $i, 3); } if (!$mappingName[$x][$i]) { $noneArray[] = array($x, $i, 4); } if (!$relLocationId) { $noneArray[] = array($x, $i, 5); } if (!$relPhoneType) { $noneArray[] = array($x, $i, 6); } $noneArray[] = array($x, $i, 2); } else { $phoneType = isset($mappingPhoneType[$x][$i]) ? $mappingPhoneType[$x][$i] : null; if (!$locationId && in_array($mappingName[$x][$i], $specialFields)) { $locationId = " "; } $defaults["mapper[{$x}][{$i}]"] = array($mappingContactType[$x][$i], $mappingName[$x][$i], $locationId, $phoneType); if (!$mappingName[$x][$i]) { $noneArray[] = array($x, $i, 1); } if (!$locationId) { $noneArray[] = array($x, $i, 2); } if (!$phoneType && !$imProvider) { $noneArray[] = array($x, $i, 3); } $noneArray[] = array($x, $i, 4); $noneArray[] = array($x, $i, 5); $noneArray[] = array($x, $i, 6); } $jsSet = true; if (CRM_Utils_Array::value($i, $mappingOperator[$x])) { $defaults["operator[{$x}][{$i}]"] = CRM_Utils_Array::value($i, $mappingOperator[$x]); } if (CRM_Utils_Array::value($i, $mappingValue[$x])) { $defaults["value[{$x}][{$i}]"] = CRM_Utils_Array::value($i, $mappingValue[$x]); } } } } //Fix for Search Builder if ($mappingType == 'Export') { $j = 7; } else { $j = 4; } $formValues = $form->exportValues(); if (!$jsSet) { if (empty($formValues)) { // Incremented length for third select box(relationship type) for ($k = 1; $k < $j; $k++) { $noneArray[] = array($x, $i, $k); } } else { if (!empty($formValues['mapper'][$x])) { foreach ($formValues['mapper'][$x] as $value) { for ($k = 1; $k < $j; $k++) { if (!isset($formValues['mapper'][$x][$i][$k]) || !$formValues['mapper'][$x][$i][$k]) { $noneArray[] = array($x, $i, $k); } else { $nullArray[] = array($x, $i, $k); } } } } else { for ($k = 1; $k < $j; $k++) { $noneArray[] = array($x, $i, $k); } } } } //Fix for Search Builder if ($mappingType == 'Export') { if (!isset($mappingId)) { if (array_key_exists($formValues['mapper'][$x][$i][1], $relationshipTypes)) { $sel->setOptions(array($sel1, $sel2, $sel5, $sel6, $sel7, $sel3, $sel4)); } else { $sel->setOptions(array($sel1, $sel2, $sel3, $sel4, $sel5, $sel6, $sel7)); } } else { $sel->setOptions(array($sel1, $sel2, $sel3, $sel4, $sel5, $sel6, $sel7)); } } else { $sel->setOptions(array($sel1, $sel2, $sel3, $sel4)); } if ($mappingType == 'Search Builder') { //CRM -2292, restricted array set $operatorArray = array('' => ts('-operator-'), '=' => '=', '!=' => '!=', '>' => '>', '<' => '<', '>=' => '>=', '<=' => '<=', 'IN' => 'IN', 'LIKE' => 'LIKE', 'IS NULL' => 'IS NULL', 'IS NOT NULL' => 'IS NOT NULL'); $form->add('select', "operator[{$x}][{$i}]", '', $operatorArray); $form->add('text', "value[{$x}][{$i}]", ''); } } //end of columnCnt for if ($mappingType == 'Search Builder') { $title = ts('Another search field'); } else { $title = ts('Select more fields'); } $form->addElement('submit', "addMore[{$x}]", $title, array('class' => 'submit-link')); } //end of block for $js = "<script type='text/javascript'>\n"; $formName = "document.{$name}"; if (!empty($nullArray)) { $js .= "var nullArray = ["; $elements = array(); $seen = array(); foreach ($nullArray as $element) { $key = "{$element[0]}, {$element[1]}, {$element[2]}"; if (!isset($seen[$key])) { $elements[] = "[{$key}]"; $seen[$key] = 1; } } $js .= implode(', ', $elements); $js .= "]"; $js .= "\nfor(var i=0;i<nullArray.length;i++) {\n {$formName}['mapper['+nullArray[i][0]+']['+nullArray[i][1]+']['+nullArray[i][2]+']'].style.display = '';\n}\n"; } if (!empty($noneArray)) { $js .= "var noneArray = ["; $elements = array(); $seen = array(); foreach ($noneArray as $element) { $key = "{$element[0]}, {$element[1]}, {$element[2]}"; if (!isset($seen[$key])) { $elements[] = "[{$key}]"; $seen[$key] = 1; } } $js .= implode(', ', $elements); $js .= "]"; $js .= "\nfor(var i=0;i<noneArray.length;i++) {\n {$formName}['mapper['+noneArray[i][0]+']['+noneArray[i][1]+']['+noneArray[i][2]+']'].style.display = 'none'; \n}\n"; } $js .= "</script>\n"; $form->assign('initHideBoxes', $js); $form->assign('columnCount', $columnCount); $form->assign('blockCount', $blockCount); $form->setDefaults($defaults); $form->setDefaultAction('refresh'); }
function buildQuickForm() { //get the saved mapping details require_once 'CRM/Core/DAO/Mapping.php'; require_once 'CRM/Contact/BAO/Contact.php'; require_once 'CRM/Core/BAO/LocationType.php'; $mappingDAO =& new CRM_Core_DAO_Mapping(); $mappingDAO->domain_id = CRM_Core_Config::domainID(); $mappingDAO->mapping_type = 'Export'; $mappingDAO->find(); $mappingArray = array(); while ($mappingDAO->fetch()) { $mappingArray[$mappingDAO->id] = $mappingDAO->name; } if (!empty($mappingArray)) { $this->assign('savedMapping', $mappingArray); $this->add('select', 'savedMapping', ts('Mapping Option'), array('' => '-select-') + $mappingArray); //if ( !isset($this->_loadedMappingId) ) { //$this->addRule('savedMapping',ts('Please select saved mappings.'), 'required'); //} $this->addElement('submit', 'loadMapping', ts('Load Mapping'), array('class' => 'form-submit')); } //to save the current mappings if (!isset($this->_loadedMappingId)) { $saveDetailsName = ts('Save this field mapping'); $this->add('text', 'saveMappingName', ts('Name')); $this->add('text', 'saveMappingDesc', ts('Description')); } else { //mapping is to be loaded from database $mapping =& new CRM_Core_DAO_MappingField(); $mapping->mapping_id = $this->_loadedMappingId; $mapping->orderBy('column_number'); $mapping->find(); $mappingName = array(); $mappingLocation = array(); $mappingContactType = array(); $mappingPhoneType = array(); while ($mapping->fetch()) { if ($mapping->name) { $mappingName[] = $mapping->name; } if ($mapping->contact_type) { $mappingContactType[] = $mapping->contact_type; } if (!empty($mapping->location_type_id)) { $mappingLocation[$mapping->column_number] = $mapping->location_type_id; } if (!empty($mapping->phone_type)) { $mappingPhoneType[$mapping->column_number] = $mapping->phone_type; } } $this->assign('loadedMapping', $this->_loadedMappingId); $getMappingName =& new CRM_Core_DAO_Mapping(); $getMappingName->id = $savedMapping; $getMappingName->mapping_type = 'Export'; $getMappingName->find(); while ($getMappingName->fetch()) { $mapperName = $getMappingName->name; } $this->assign('savedName', $mapperName); $this->add('hidden', 'mappingId', $this->_loadedMappingId); $this->addElement('checkbox', 'updateMapping', ts('Update this field mapping'), null); $saveDetailsName = ts('Save as a new field mapping'); $this->add('text', 'saveMappingName', ts('Name')); $this->add('text', 'saveMappingDesc', ts('Description')); } $this->addElement('checkbox', 'saveMapping', $saveDetailsName, null, array('onclick' => "showSaveDetails(this)")); $this->addFormRule(array('CRM_Contact_Form_Task_Export_Map', 'formRule')); //-------- end of saved mapping stuff --------- $this->_defaults = array(); $hasLocationTypes = array(); $contactId = array(); $fields = array(); $fields['Individual'] =& CRM_Contact_BAO_Contact::exportableFields('Individual', false, true); $fields['Household'] =& CRM_Contact_BAO_Contact::exportableFields('Household', false, true); $fields['Organization'] =& CRM_Contact_BAO_Contact::exportableFields('Organization', false, true); foreach ($fields as $key => $value) { foreach ($value as $key1 => $value1) { $this->_mapperFields[$key][$key1] = $value1['title']; $hasLocationTypes[$key][$key1] = $value1['hasLocationType']; } } $mapperKeys = array_keys($this->_mapperFields); $this->_location_types =& CRM_Core_PseudoConstant::locationType(); $defaultLocationType =& CRM_Core_BAO_LocationType::getDefault(); /* FIXME: dirty hack to make the default option show up first. This * avoids a mozilla browser bug with defaults on dynamically constructed * selector widgets. */ if ($defaultLocationType) { $defaultLocation = $this->_location_types[$defaultLocationType->id]; unset($this->_location_types[$defaultLocationType->id]); $this->_location_types = array($defaultLocationType->id => $defaultLocation) + $this->_location_types; } $sel1 = array('' => '-select-') + CRM_Core_SelectValues::contactType(); foreach ($sel1 as $key => $sel) { if ($key) { $sel2[$key] = $this->_mapperFields[$key]; } } $sel3[''] = null; $phoneTypes = CRM_Core_SelectValues::phoneType(); foreach ($sel1 as $k => $sel) { if ($k) { foreach ($this->_location_types as $key => $value) { $sel4[$k]['phone'][$key] =& $phoneTypes; } } } foreach ($sel1 as $k => $sel) { if ($k) { foreach ($this->_mapperFields[$k] as $key => $value) { if ($hasLocationTypes[$k][$key]) { $sel3[$k][$key] = $this->_location_types; } else { $sel3[$key] = null; } } } } // print_r($sel3); $this->_defaults = array(); $js = "<script type='text/javascript'>\n"; $formName = "document.{$this->_name}"; //used to warn for mismatch column count or mismatch mapping $warning = 0; for ($i = 0; $i < $this->_columnCount; $i++) { $sel =& $this->addElement('hierselect', "mapper[{$i}]", ts('Mapper for Field %1', array(1 => $i)), null); $jsSet = false; if (isset($this->_loadedMappingId)) { $locationId = isset($mappingLocation[$i]) ? $mappingLocation[$i] : 0; if (isset($mappingName[$i])) { if (is_array($this->_mapperFields[$mappingContactType[$i]])) { $phoneType = isset($mappingPhoneType[$i]) ? $mappingPhoneType[$i] : null; $mappingHeader = array_keys($this->_mapperFields[$mappingContactType[$i]], $mappingName[$i]); $defaults["mapper[{$i}]"] = array($mappingContactType[$i], $mappingHeader[0], $locationId, $phoneType); if (!$mappingHeader[0]) { $js .= "{$formName}['mapper[{$i}][1]'].style.display = 'none';\n"; } if (!$locationId) { $js .= "{$formName}['mapper[{$i}][2]'].style.display = 'none';\n"; } if (!$phoneType) { $js .= "{$formName}['mapper[{$i}][3]'].style.display = 'none';\n"; } $jsSet = true; } } } //$formValues = $this->controller->exportValues( $this->_name ); $formValues = $_POST; // using $_POST since export values don't give values on first submit /* if ( ! $jsSet && empty( $formValues ) ) { for ( $k = 1; $k < 4; $k++ ) { $js .= "{$formName}['mapper[$i][$k]'].style.display = 'none';\n"; } } */ if (!$jsSet) { if (empty($formValues)) { for ($k = 1; $k < 4; $k++) { $js .= "{$formName}['mapper[{$i}][{$k}]'].style.display = 'none';\n"; } } else { foreach ($formValues['mapper'] as $value) { for ($k = 1; $k < 4; $k++) { if (!$formValues['mapper'][$i][$k]) { $js .= "{$formName}['mapper[{$i}][{$k}]'].style.display = 'none';\n"; } } } } } $sel->setOptions(array($sel1, $sel2, $sel3, $sel4)); //set the defaults on load mapping } $js .= "</script>\n"; $this->assign('initHideBoxes', $js); $this->assign('columnCount', $this->_columnCount); $this->setDefaults($defaults); $this->addElement('submit', 'addMore', ts('Select more fields'), array('class' => 'form-submit')); $this->setDefaultAction('refresh'); $this->addButtons(array(array('type' => 'back', 'name' => ts('<< Previous')), array('type' => 'next', 'name' => ts('Export >>'), 'spacing' => ' '), array('type' => 'cancel', 'name' => ts('Done')))); }