/** * View summary details of a contact * * @return void * @access public */ function view() { $params = array(); $defaults = array(); $ids = array(); $params['id'] = $params['contact_id'] = $this->_contactId; $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, $ids); $this->assign('pageTitle', $contact->sort_name); return parent::view(); }
public function preProcess() { $params = $defaults = $ids = array(); $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); $params['id'] = $params['contact_id'] = $this->_contactId; $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, $ids); $this->_displayName = $contact->display_name; $this->_email = $contact->email; CRM_Utils_System::setTitle(ts('Create User Record for %1', array(1 => $this->_displayName))); }
/** * @param bool $useWhere * * @return mixed|void */ public function delete($useWhere = FALSE) { $this->load_associations(); $contacts_to_delete = array(); foreach ($this->participants as $participant) { $defaults = array(); $params = array('id' => $participant->contact_id); $temporary_contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults); if ($temporary_contact->is_deleted) { $contacts_to_delete[$temporary_contact->id] = 1; } $participant->delete(); } foreach (array_keys($contacts_to_delete) as $contact_id) { CRM_Contact_BAO_Contact::deleteContact($contact_id); } return parent::delete(); }
/** * test case for retrieve( ) * test with all values. */ function testRetrieve() { //take the common contact params $params = $this->contactParams(); $params['note'] = 'test note'; $params['create_employer'] = 'Yahoo'; require_once 'CRM/Contact/BAO/Contact.php'; //create the contact with given params. $contact = CRM_Contact_BAO_Contact::create($params); //Now check $contact is object of contact DAO.. $this->assertType('CRM_Contact_DAO_Contact', $contact, 'Check for created object'); $contactId = $contact->id; //create employee of relationship. require_once 'CRM/Contact/BAO/Contact/Utils.php'; CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contactId, $params['create_employer']); //retrieve the contact values from database. $values = array(); $searchParams = array('contact_id' => $contactId); $retrieveContact = CRM_Contact_BAO_Contact::retrieve($searchParams, $values); //Now check $retrieveContact is object of contact DAO.. $this->assertType('CRM_Contact_DAO_Contact', $retrieveContact, 'Check for retrieve object'); //Now check the ids. $this->assertEquals($contactId, $retrieveContact->id, 'Check for contact id'); //Now check values retrieve from database with params. $this->assertEquals($params['first_name'], $values['first_name'], 'Check for first name creation.'); $this->assertEquals($params['last_name'], $values['last_name'], 'Check for last name creation.'); $this->assertEquals($params['contact_type'], $values['contact_type'], 'Check for contact type creation.'); //Now check values of address // $this->assertAttributesEquals( CRM_Utils_Array::value( 'address', $params ), // CRM_Utils_Array::value( 'address', $values ) ); //Now check values of email $this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['email']), CRM_Utils_Array::value('1', $values['email'])); //Now check values of phone $this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['phone']), CRM_Utils_Array::value('1', $values['phone'])); //Now check values of mobile $this->assertAttributesEquals(CRM_Utils_Array::value('2', $params['phone']), CRM_Utils_Array::value('2', $values['phone'])); //Now check values of openid $this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['openid']), CRM_Utils_Array::value('1', $values['openid'])); //Now check values of im $this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['im']), CRM_Utils_Array::value('1', $values['im'])); //Now check values of Note Count. $this->assertEquals(1, $values['noteTotalCount'], 'Check for total note count'); foreach ($values['note'] as $key => $val) { $retrieveNote = CRM_Utils_Array::value('note', $val); //check the note value $this->assertEquals($params['note'], $retrieveNote, 'Check for note'); } //Now check values of Relationship Count. $this->assertEquals(1, $values['relationship']['totalCount'], 'Check for total relationship count'); foreach ($values['relationship']['data'] as $key => $val) { //Now check values of Relationship organization. $this->assertEquals($params['create_employer'], $val['name'], 'Check for organization'); //Now check values of Relationship type. $this->assertEquals('Employee of', $val['relation'], 'Check for relationship type'); //delete the organization. Contact::delete(CRM_Utils_Array::value('cid', $val)); } //cleanup DB by deleting the contact Contact::delete($contactId); }
/** * build all the data structures needed to build the form * * @return void * @access public */ function preProcess() { $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'add'); $this->_dedupeButtonName = $this->getButtonName('refresh', 'dedupe'); $this->_duplicateButtonName = $this->getButtonName('upload', 'duplicate'); $session =& CRM_Core_Session::singleton(); if ($this->_action == CRM_Core_Action::ADD) { // check for add contacts permissions require_once 'CRM/Core/Permission.php'; if (!CRM_Core_Permission::check('add contacts')) { CRM_Utils_System::permissionDenied(); return; } $this->_contactType = CRM_Utils_Request::retrieve('ct', 'String', $this, true, null, 'REQUEST'); if (!in_array($this->_contactType, array('Individual', 'Household', 'Organization'))) { CRM_Core_Error::statusBounce(ts('Could not get a contact_id and/or contact_type')); } $this->_contactSubType = CRM_Utils_Request::retrieve('cst', 'String', $this); $this->_gid = CRM_Utils_Request::retrieve('gid', 'Integer', CRM_Core_DAO::$_nullObject, false, null, 'GET'); $this->_tid = CRM_Utils_Request::retrieve('tid', 'Integer', CRM_Core_DAO::$_nullObject, false, null, 'GET'); if ($this->_contactSubType) { CRM_Utils_System::setTitle(ts('New %1', array(1 => $this->_contactSubType))); } else { $title = ts('New Individual'); if ($this->_contactType == 'Household') { $title = ts('New Household'); } else { if ($this->_contactType == 'Organization') { $title = ts('New Organization'); } } CRM_Utils_System::setTitle($title); } $session->pushUserContext(CRM_Utils_System::url('civicrm/dashboard', 'reset=1')); $this->_contactId = null; } else { //update mode if (!$this->_contactId) { $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, true); } if ($this->_contactId) { require_once 'CRM/Contact/BAO/Contact.php'; $contact =& new CRM_Contact_DAO_Contact(); $contact->id = $this->_contactId; if (!$contact->find(true)) { CRM_Core_Error::statusBounce(ts('contact does not exist: %1', array(1 => $this->_contactId))); } $this->_contactType = $contact->contact_type; $this->_contactSubType = $contact->contact_sub_type; // check for permissions require_once 'CRM/Contact/BAO/Contact/Permission.php'; if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) { CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to edit this contact.')); } list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_contactId); CRM_Utils_System::setTitle($displayName, $contactImage . ' ' . $displayName); $session->pushUserContext(CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId)); $values = $this->get('values'); // get contact values. if (!empty($values)) { $this->_values = $values; } else { $params = array('id' => $this->_contactId, 'contact_id' => $this->_contactId); $contact = CRM_Contact_BAO_Contact::retrieve($params, $this->_values, true); $this->set('values', $this->_values); } } else { CRM_Core_Error::statusBounce(ts('Could not get a contact_id and/or contact_type')); } } $this->_editOptions = $this->get('contactEditOptions'); if (CRM_Utils_System::isNull($this->_editOptions)) { require_once 'CRM/Core/BAO/Preferences.php'; $this->_editOptions = CRM_Core_BAO_Preferences::valueOptions('contact_edit_options', true, null, false, 'name', true, 'AND v.filter = 0'); $this->set('contactEditOptions', $this->_editOptions); } // build demographics only for Individual contact type if ($this->_contactType != 'Individual' && array_key_exists('Demographics', $this->_editOptions)) { unset($this->_editOptions['Demographics']); } // in update mode don't show notes if ($this->_contactId && array_key_exists('Notes', $this->_editOptions)) { unset($this->_editOptions['Notes']); } $this->assign('editOptions', $this->_editOptions); $this->assign('contactType', $this->_contactType); $this->assign('contactSubType', $this->_contactSubType); // get the location blocks. $this->_blocks = $this->get('blocks'); if (CRM_Utils_System::isNull($this->_blocks)) { $this->_blocks = CRM_Core_BAO_Preferences::valueOptions('contact_edit_options', true, null, false, 'name', true, 'AND v.filter = 1'); $this->set('blocks', $this->_blocks); } $this->assign('blocks', $this->_blocks); if (array_key_exists('CustomData', $this->_editOptions)) { //only custom data has preprocess hence directly call it CRM_Custom_Form_CustomData::preProcess($this, null, $this->_contactSubType, 1, $this->_contactType, $this->_contactId); } // this is needed for custom data. $this->assign('entityID', $this->_contactId); // also keep the convention. $this->assign('contactId', $this->_contactId); // location blocks. CRM_Contact_Form_Location::preProcess($this); }
/** * format params for update and fill mode * * @param $params array referance to an array containg all the * values for import * @param $onDuplicate int * @param $cid int contact id */ function formatParams(&$params, $onDuplicate, $cid) { if ($onDuplicate == CRM_Import_Parser::DUPLICATE_SKIP) { return; } $contactParams = array('contact_id' => $cid); $defaults = array(); $contactObj = CRM_Contact_BAO_Contact::retrieve($contactParams, $defaults); $modeUpdate = $modeFill = false; if ($onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) { $modeUpdate = true; } if ($onDuplicate == CRM_Import_Parser::DUPLICATE_FILL) { $modeFill = true; } require_once 'CRM/Core/BAO/CustomGroup.php'; $groupTree = CRM_Core_BAO_CustomGroup::getTree($params['contact_type'], CRM_Core_DAO::$_nullObject, $cid, 0, null); CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults, false, false); $contact = get_object_vars($contactObj); $location = null; foreach ($params as $key => $value) { if ($key == 'id' || $key == 'contact_type') { continue; } if ($key == 'location') { $location = true; } else { if (in_array($key, array('email_greeting', 'postal_greeting', 'addressee'))) { // CRM-4575, need to null custom if ($params["{$key}_id"] != 4) { $params["{$key}_custom"] = 'null'; } unset($params[$key]); } else { if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key)) { $custom = true; } else { $getValue = CRM_Utils_Array::retrieveValueRecursive($contact, $key); if ($key == 'contact_source') { $params['source'] = $params[$key]; unset($params[$key]); } if ($modeFill && isset($getValue)) { unset($params[$key]); } } } } } if ($location) { for ($loc = 1; $loc <= count($params['location']); $loc++) { //if location block is already present for the contact //then do not fill any data for that location type, CRM-4424 if ($modeFill) { foreach ($contact['location'] as $location => $locationDetails) { $getValue = CRM_Utils_Array::value('location_type_id', $locationDetails); if (isset($getValue) && $getValue == $params['location'][$loc]['location_type_id']) { unset($params['location'][$loc]); break; } } } if (array_key_exists('address', $contact['location'][$loc])) { $fields = array('street_address', 'city', 'state_province_id', 'postal_code', 'postal_code_suffix', 'country_id'); foreach ($fields as $field) { $getValue = CRM_Utils_Array::retrieveValueRecursive($contact['location'][$loc]['address'], $field); if ($modeFill && isset($getValue)) { unset($params['location'][$loc]['address'][$field]); } } } $fields = array('email' => 'email', 'phone' => 'phone', 'im' => 'name'); foreach ($fields as $key => $field) { if (array_key_exists($key, $contact['location'][$loc])) { for ($c = 1; $c <= count($params['location'][$loc][$key]); $c++) { $getValue = CRM_Utils_Array::retrieveValueRecursive($contact['location'][$loc][$key][$c], $field); if ($modeFill && isset($getValue)) { unset($params['location'][$loc][$key][$c][$field]); } } } } } } }
/** * Heart of the vCard data assignment process. * * The runner gets all the metadata for the contact and calls the writeVcard method to output the vCard * to the user. */ public function run() { $this->preProcess(); $params = array(); $defaults = array(); $ids = array(); $params['id'] = $params['contact_id'] = $this->_contactId; $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, $ids); // now that we have the contact's data - let's build the vCard // TODO: non-US-ASCII support (requires changes to the Contact_Vcard_Build class) $vcardNames = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'vcard_name')); $vcard = new Contact_Vcard_Build('2.1'); if ($defaults['contact_type'] == 'Individual') { $vcard->setName(CRM_Utils_Array::value('last_name', $defaults), CRM_Utils_Array::value('first_name', $defaults), CRM_Utils_Array::value('middle_name', $defaults), CRM_Utils_Array::value('prefix', $defaults), CRM_Utils_Array::value('suffix', $defaults)); $organizationName = CRM_Utils_Array::value('organization_name', $defaults); if ($organizationName !== NULL) { $vcard->addOrganization($organizationName); } } elseif ($defaults['contact_type'] == 'Organization') { $vcard->setName($defaults['organization_name'], '', '', '', ''); } elseif ($defaults['contact_type'] == 'Household') { $vcard->setName($defaults['household_name'], '', '', '', ''); } $vcard->setFormattedName($defaults['display_name']); $vcard->setSortString($defaults['sort_name']); if (!empty($defaults['nick_name'])) { $vcard->addNickname($defaults['nick_name']); } if (!empty($defaults['job_title'])) { $vcard->setTitle($defaults['job_title']); } if (!empty($defaults['birth_date_display'])) { $vcard->setBirthday(CRM_Utils_Array::value('birth_date_display', $defaults)); } if (!empty($defaults['home_URL'])) { $vcard->setURL($defaults['home_URL']); } // TODO: $vcard->setGeo($lat, $lon); if (!empty($defaults['address'])) { $stateProvices = CRM_Core_PseudoConstant::stateProvince(); $countries = CRM_Core_PseudoConstant::country(); foreach ($defaults['address'] as $location) { // we don't keep PO boxes in separate fields $pob = ''; $extend = CRM_Utils_Array::value('supplemental_address_1', $location); if (!empty($location['supplemental_address_2'])) { $extend .= ', ' . $location['supplemental_address_2']; } $street = CRM_Utils_Array::value('street_address', $location); $locality = CRM_Utils_Array::value('city', $location); $region = NULL; if (!empty($location['state_province_id'])) { $region = $stateProvices[CRM_Utils_Array::value('state_province_id', $location)]; } $country = NULL; if (!empty($location['country_id'])) { $country = $countries[CRM_Utils_Array::value('country_id', $location)]; } $postcode = CRM_Utils_Array::value('postal_code', $location); if (!empty($location['postal_code_suffix'])) { $postcode .= '-' . $location['postal_code_suffix']; } $vcard->addAddress($pob, $extend, $street, $locality, $region, $postcode, $country); $vcardName = $vcardNames[$location['location_type_id']]; if ($vcardName) { $vcard->addParam('TYPE', $vcardName); } if (!empty($location['is_primary'])) { $vcard->addParam('TYPE', 'PREF'); } } } if (!empty($defaults['phone'])) { foreach ($defaults['phone'] as $phone) { $vcard->addTelephone($phone['phone']); $vcardName = $vcardNames[$phone['location_type_id']]; if ($vcardName) { $vcard->addParam('TYPE', $vcardName); } if ($phone['is_primary']) { $vcard->addParam('TYPE', 'PREF'); } } } if (!empty($defaults['email'])) { foreach ($defaults['email'] as $email) { $vcard->addEmail($email['email']); $vcardName = $vcardNames[$email['location_type_id']]; if ($vcardName) { $vcard->addParam('TYPE', $vcardName); } if ($email['is_primary']) { $vcard->addParam('TYPE', 'PREF'); } } } // all that's left is sending the vCard to the browser $filename = CRM_Utils_String::munge($defaults['display_name']); $vcard->send($filename . '.vcf', 'attachment', 'utf-8'); CRM_Utils_System::civiExit(); }
function postProcess() { if (!array_key_exists('event', $this->_submitValues)) { return; } // XXX de facto primary key $email_to_contact_id = array(); foreach ($this->_submitValues['event'] as $event_id => $participants) { foreach ($participants['participant'] as $participant_id => $fields) { if (array_key_exists($fields['email'], $email_to_contact_id)) { $contact_id = $email_to_contact_id[$fields['email']]; } else { $contact_id = self::find_or_create_contact($this->getContactID(), $fields); $email_to_contact_id[$fields['email']] = $contact_id; } $participant = $this->cart->get_event_in_cart_by_event_id($event_id)->get_participant_by_id($participant_id); if ($participant->contact_id && $contact_id != $participant->contact_id) { $defaults = array(); $params = array('id' => $participant->contact_id); $temporary_contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults); foreach ($this->cart->get_subparticipants($participant) as $subparticipant) { $subparticipant->contact_id = $contact_id; $subparticipant->save(); } $participant->contact_id = $contact_id; $participant->save(); if ($temporary_contact->is_deleted) { #ARGH a permissions check prevents us from using skipUndelete, #so we potentially leave records pointing to this contact for now #CRM_Contact_BAO_Contact::deleteContact($temporary_contact->id); $temporary_contact->delete(); } } //TODO security check that participant ids are already in this cart $participant_params = array('id' => $participant_id, 'cart_id' => $this->cart->id, 'event_id' => $event_id, 'contact_id' => $contact_id, 'email' => $fields['email']); $participant = new CRM_Event_Cart_BAO_MerParticipant($participant_params); $participant->save(); $this->cart->add_participant_to_cart($participant); if (array_key_exists('field', $this->_submitValues) && array_key_exists($participant_id, $this->_submitValues['field'])) { $custom_fields = array_merge($participant->get_form()->get_participant_custom_data_fields()); CRM_Contact_BAO_Contact::createProfileContact($this->_submitValues['field'][$participant_id], $custom_fields, $contact_id); } } } $this->cart->save(); }
/** * Heart of the viewing process. The runner gets all the meta data for * the contact and calls the appropriate type of page to view. * * @return void * @access public * */ function preProcess() { parent::preProcess(); // we need to retrieve privacy preferences // to (un)display the 'Send an Email' link $params = array(); $defaults = array(); $ids = array(); $params['id'] = $params['contact_id'] = $this->_contactId; CRM_Contact_BAO_Contact::retrieve($params, $defaults, $ids); CRM_Contact_BAO_Contact::resolveDefaults($defaults); $this->assign($defaults); }
/** * Function to get the list the export fields * * @param int $selectAll user preference while export * @param array $ids contact ids * @param array $params associated array of fields * @param string $order order by clause * @param array $associated array of fields * @param array $moreReturnProperties additional return fields * @param int $exportMode export mode * @param string $componentClause component clause * * @static * @access public */ static function exportComponents($selectAll, $ids, $params, $order = null, $fields = null, $moreReturnProperties = null, $exportMode = CRM_Export_Form_Select::CONTACT_EXPORT, $componentClause = null) { $headerRows = array(); $primary = false; $returnProperties = array(); $origFields = $fields; $queryMode = null; $paymentFields = false; $phoneTypes = CRM_Core_PseudoConstant::phoneType(); $imProviders = CRM_Core_PseudoConstant::IMProvider(); $contactRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, null, null, null, true, 'label', false); $queryMode = CRM_Contact_BAO_Query::MODE_CONTACTS; switch ($exportMode) { case CRM_Export_Form_Select::CONTRIBUTE_EXPORT: $queryMode = CRM_Contact_BAO_Query::MODE_CONTRIBUTE; break; case CRM_Export_Form_Select::EVENT_EXPORT: $queryMode = CRM_Contact_BAO_Query::MODE_EVENT; break; case CRM_Export_Form_Select::MEMBER_EXPORT: $queryMode = CRM_Contact_BAO_Query::MODE_MEMBER; break; case CRM_Export_Form_Select::PLEDGE_EXPORT: $queryMode = CRM_Contact_BAO_Query::MODE_PLEDGE; break; case CRM_Export_Form_Select::CASE_EXPORT: $queryMode = CRM_Contact_BAO_Query::MODE_CASE; break; } require_once 'CRM/Core/BAO/CustomField.php'; if ($fields) { //construct return properties $locationTypes =& CRM_Core_PseudoConstant::locationType(); $locationTypeFields = 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'); foreach ($fields as $key => $value) { $phoneTypeId = null; $imProviderId = null; $relationshipTypes = $fieldName = CRM_Utils_Array::value(1, $value); if (!$fieldName) { continue; } // get phoneType id and IM service provider id seperately if ($fieldName == 'phone') { $phoneTypeId = CRM_Utils_Array::value(3, $value); } else { if ($fieldName == 'im') { $imProviderId = CRM_Utils_Array::value(3, $value); } } if (array_key_exists($relationshipTypes, $contactRelationshipTypes)) { if (CRM_Utils_Array::value(2, $value)) { $relationField = CRM_Utils_Array::value(2, $value); if (trim(CRM_Utils_Array::value(3, $value))) { $relLocTypeId = CRM_Utils_Array::value(3, $value); } else { $relLocTypeId = 1; } if ($relationField == 'phone') { $relPhoneTypeId = CRM_Utils_Array::value(4, $value); } else { if ($relationField == 'im') { $relIMProviderId = CRM_Utils_Array::value(4, $value); } } } else { if (CRM_Utils_Array::value(4, $value)) { $relationField = CRM_Utils_Array::value(4, $value); $relLocTypeId = CRM_Utils_Array::value(5, $value); if ($relationField == 'phone') { $relPhoneTypeId = CRM_Utils_Array::value(6, $value); } else { if ($relationField == 'im') { $relIMProviderId = CRM_Utils_Array::value(6, $value); } } } } } $contactType = CRM_Utils_Array::value(0, $value); $locTypeId = CRM_Utils_Array::value(2, $value); $phoneTypeId = CRM_Utils_Array::value(3, $value); if ($relationField) { if (in_array($relationField, $locationTypeFields)) { if ($relPhoneTypeId) { $returnProperties[$relationshipTypes]['location'][$locationTypes[$relLocTypeId]]['phone-' . $relPhoneTypeId] = 1; } else { if ($relIMProviderId) { $returnProperties[$relationshipTypes]['location'][$locationTypes[$relLocTypeId]]['im-' . $relIMProviderId] = 1; } else { $returnProperties[$relationshipTypes]['location'][$locationTypes[$relLocTypeId]][$relationField] = 1; } } $relPhoneTypeId = $relIMProviderId = null; } else { $returnProperties[$relationshipTypes][$relationField] = 1; } } else { if (is_numeric($locTypeId)) { if ($phoneTypeId) { $returnProperties['location'][$locationTypes[$locTypeId]]['phone-' . $phoneTypeId] = 1; } else { if (isset($imProviderId)) { //build returnProperties for IM service provider $returnProperties['location'][$locationTypes[$locTypeId]]['im-' . $imProviderId] = 1; } else { $returnProperties['location'][$locationTypes[$locTypeId]][$fieldName] = 1; } } } else { //hack to fix component fields if ($fieldName == 'event_id') { $returnProperties['event_title'] = 1; } else { $returnProperties[$fieldName] = 1; } } } } // hack to add default returnproperty based on export mode if ($exportMode == CRM_Export_Form_Select::CONTRIBUTE_EXPORT) { $returnProperties['contribution_id'] = 1; } else { if ($exportMode == CRM_Export_Form_Select::EVENT_EXPORT) { $returnProperties['participant_id'] = 1; } else { if ($exportMode == CRM_Export_Form_Select::MEMBER_EXPORT) { $returnProperties['membership_id'] = 1; } else { if ($exportMode == CRM_Export_Form_Select::PLEDGE_EXPORT) { $returnProperties['pledge_id'] = 1; } else { if ($exportMode == CRM_Export_Form_Select::CASE_EXPORT) { $returnProperties['case_id'] = 1; } } } } } } else { $primary = true; $fields = CRM_Contact_BAO_Contact::exportableFields('All', true, true); foreach ($fields as $key => $var) { if ($key && substr($key, 0, 6) != 'custom') { //for CRM=952 $returnProperties[$key] = 1; } } if ($primary) { $returnProperties['location_type'] = 1; $returnProperties['im_provider'] = 1; $returnProperties['phone_type_id'] = 1; $returnProperties['provider_id'] = 1; $returnProperties['current_employer'] = 1; } $extraReturnProperties = array(); $paymentFields = false; switch ($queryMode) { case CRM_Contact_BAO_Query::MODE_EVENT: $paymentFields = true; $paymentTableId = "participant_id"; break; case CRM_Contact_BAO_Query::MODE_MEMBER: $paymentFields = true; $paymentTableId = "membership_id"; break; case CRM_Contact_BAO_Query::MODE_PLEDGE: require_once 'CRM/Pledge/BAO/Query.php'; $extraReturnProperties = CRM_Pledge_BAO_Query::extraReturnProperties($queryMode); $paymentFields = true; $paymentTableId = "pledge_payment_id"; break; case CRM_Contact_BAO_Query::MODE_CASE: require_once 'CRM/Case/BAO/Query.php'; $extraReturnProperties = CRM_Case_BAO_Query::extraReturnProperties($queryMode); break; } if ($queryMode != CRM_Contact_BAO_Query::MODE_CONTACTS) { $componentReturnProperties =& CRM_Contact_BAO_Query::defaultReturnProperties($queryMode); $returnProperties = array_merge($returnProperties, $componentReturnProperties); if (!empty($extraReturnProperties)) { $returnProperties = array_merge($returnProperties, $extraReturnProperties); } // unset groups, tags, notes for components foreach (array('groups', 'tags', 'notes') as $value) { unset($returnProperties[$value]); } } } if ($moreReturnProperties) { $returnProperties = array_merge($returnProperties, $moreReturnProperties); } $query =& new CRM_Contact_BAO_Query(0, $returnProperties, null, false, false, $queryMode); list($select, $from, $where) = $query->query(); // make sure the groups stuff is included only if specifically specified // by the fields param (CRM-1969), else we limit the contacts outputted to only // ones that are part of a group if (CRM_Utils_Array::value('groups', $returnProperties)) { $oldClause = "contact_a.id = civicrm_group_contact.contact_id"; $newClause = " ( {$oldClause} AND civicrm_group_contact.status = 'Added' OR civicrm_group_contact.status IS NULL ) "; // total hack for export, CRM-3618 $from = str_replace($oldClause, $newClause, $from); } if ($componentClause) { if (empty($where)) { $where = "WHERE {$componentClause}"; } else { $where .= " AND {$componentClause}"; } } $queryString = "{$select} {$from} {$where}"; if (CRM_Utils_Array::value('tags', $returnProperties) || CRM_Utils_Array::value('groups', $returnProperties) || CRM_Utils_Array::value('notes', $returnProperties) || $query->_useGroupBy) { $queryString .= " GROUP BY contact_a.id"; } if ($order) { list($field, $dir) = explode(' ', $order, 2); $field = trim($field); if (CRM_Utils_Array::value($field, $returnProperties)) { $queryString .= " ORDER BY {$order}"; } } //hack for student data require_once 'CRM/Core/OptionGroup.php'; $multipleSelectFields = array('preferred_communication_method' => 1); if (CRM_Core_Permission::access('Quest')) { require_once 'CRM/Quest/BAO/Student.php'; $studentFields = array(); $studentFields = CRM_Quest_BAO_Student::$multipleSelectFields; $multipleSelectFields = array_merge($multipleSelectFields, $studentFields); } $dao =& CRM_Core_DAO::executeQuery($queryString, CRM_Core_DAO::$_nullArray); $header = false; $addPaymentHeader = false; if ($paymentFields) { $addPaymentHeader = true; //special return properties for event and members $paymentHeaders = array(ts('Total Amount'), ts('Contribution Status'), ts('Received Date'), ts('Payment Instrument'), ts('Transaction ID')); // get payment related in for event and members require_once 'CRM/Contribute/BAO/Contribution.php'; $paymentDetails = CRM_Contribute_BAO_Contribution::getContributionDetails($exportMode, $ids); } $componentDetails = $headerRows = array(); $setHeader = true; while ($dao->fetch()) { $row = array(); //first loop through returnproperties so that we return what is required, and in same order. $relationshipField = 0; foreach ($returnProperties as $field => $value) { //we should set header only once if ($setHeader) { if (isset($query->_fields[$field]['title'])) { $headerRows[] = $query->_fields[$field]['title']; } else { if ($field == 'phone_type_id') { $headerRows[] = 'Phone Type'; } else { if ($field == 'provider_id') { $headerRows[] = 'Im Service Provider'; } else { if (is_array($value) && $field == 'location') { // fix header for location type case foreach ($value as $ltype => $val) { foreach (array_keys($val) as $fld) { $type = explode('-', $fld); $hdr = "{$ltype}-" . $query->_fields[$type[0]]['title']; if (CRM_Utils_Array::value(1, $type)) { if (CRM_Utils_Array::value(0, $type) == 'phone') { $hdr .= "-" . CRM_Utils_Array::value($type[1], $phoneTypes); } else { if (CRM_Utils_Array::value(0, $type) == 'im') { $hdr .= "-" . CRM_Utils_Array::value($type[1], $imProviders); } } } $headerRows[] = $hdr; } } } else { if (substr($field, 0, 5) == 'case_') { if ($query->_fields['case'][$field]['title']) { $headerRows[] = $query->_fields['case'][$field]['title']; } else { if ($query->_fields['activity'][$field]['title']) { $headerRows[] = $query->_fields['activity'][$field]['title']; } } } else { if (array_key_exists($field, $contactRelationshipTypes)) { foreach ($value as $relationField => $relationValue) { if (is_array($relationValue)) { foreach ($relationValue as $locType => $locValue) { if ($relationField == 'location') { foreach ($locValue as $locKey => $dont) { list($serviceProvider, $serviceProviderID) = explode('-', $locKey); if ($serviceProvider == 'phone') { $headerRows[] = $contactRelationshipTypes[$field] . ' : ' . $locType . ' - ' . $serviceProvider . ' - ' . CRM_Utils_Array::value($serviceProviderID, $phoneTypes, 'Primary'); } else { if ($serviceProvider == 'im') { $headerRows[] = $contactRelationshipTypes[$field] . ' : ' . $locType . ' - ' . $serviceProvider . ' - ' . CRM_Utils_Array::value($serviceProviderID, $imProviders, 'Primary'); } else { $headerRows[] = $contactRelationshipTypes[$field] . ' : ' . $locType . ' - ' . $query->_fields[$locKey]['title']; } } } } } } else { if ($query->_fields[$relationField]['title']) { $headerRows[] = $contactRelationshipTypes[$field] . ' : ' . $query->_fields[$relationField]['title']; } else { $headerRows[] = $contactRelationshipTypes[$field] . ' : ' . $relationField; } } } } else { $headerRows[] = $field; } } } } } } } //build row values (data) if (property_exists($dao, $field)) { $fieldValue = $dao->{$field}; // to get phone type from phone type id if ($field == 'phone_type_id') { $fieldValue = $phoneTypes[$fieldValue]; } else { if ($field == 'provider_id') { $fieldValue = CRM_Utils_Array::value($fieldValue, $imProviders); } } } else { $fieldValue = ''; } if ($field == 'id') { $row[$field] = $dao->contact_id; } else { if ($field == 'pledge_balance_amount') { //special case for calculated field $row[$field] = $dao->pledge_amount - $dao->pledge_total_paid; } else { if ($field == 'pledge_next_pay_amount') { //special case for calculated field $row[$field] = $dao->pledge_next_pay_amount + $dao->pledge_outstanding_amount; } else { if (is_array($value) && $field == 'location') { // fix header for location type case foreach ($value as $ltype => $val) { foreach (array_keys($val) as $fld) { $type = explode('-', $fld); $fldValue = "{$ltype}-" . $type[0]; if (CRM_Utils_Array::value(1, $type)) { $fldValue .= "-" . $type[1]; } $row[$fldValue] = $dao->{$fldValue}; } } } else { if (array_key_exists($field, $contactRelationshipTypes)) { list($id, $direction) = explode('_', $field, 2); require_once 'api/v2/Relationship.php'; require_once 'CRM/Contact/BAO/Contact.php'; require_once 'CRM/Core/BAO/CustomValueTable.php'; require_once 'CRM/Core/BAO/CustomQuery.php'; $params['relationship_type_id'] = $contactRelationshipTypes[$field]; $contact_id['contact_id'] = $dao->contact_id; //Get relationships $val = civicrm_contact_relationship_get($contact_id, null, $params); if (is_array($val['result'])) { asort($val['result']); } $is_valid = null; $data = null; if ($val['result']) { foreach ($val['result'] as $k => $v) { //consider only active relationships if ($v['is_active'] && $v['rtype'] == $direction) { $cID['contact_id'] = $v['cid']; if ($cID) { //Get Contact Details $data = CRM_Contact_BAO_Contact::retrieve($cID, $defaults); } $is_valid = true; break; } } } $relCustomIDs = array(); foreach ($value as $relationkey => $relationvalue) { if ($val['result'] && ($cfID = CRM_Core_BAO_CustomField::getKeyID($relationkey))) { foreach ($val['result'] as $k1 => $v1) { $contID = $v1['cid']; $param1 = array('entityID' => $contID, $relationkey => 1); $getcustomValue = CRM_Core_BAO_CustomValueTable::getValues($param1); $custom_ID = CRM_Core_BAO_CustomField::getKeyID($relationkey); if ($cfID = CRM_Core_BAO_CustomField::getKeyID($relationkey)) { if (empty($query->_options)) { $relCustomIDs[$cfID] = array(); $relQuery = new CRM_Core_BAO_CustomQuery($relCustomIDs); $relQuery->query(); $relOptions = $relQuery->_options; } else { $relOptions = $query->_options; } $custom_data = CRM_Core_BAO_CustomField::getDisplayValue($getcustomValue[$relationkey], $cfID, $relOptions); } else { $custom_data = ''; } } } //Get all relationships type custom fields list($id, $atype, $btype) = explode('_', $field); $relCustomData = CRM_Core_BAO_CustomField::getFields('Relationship', null, null, $id, null, null); $tmpArray = array_keys($relCustomData); $customIDs = array(); foreach ($tmpArray as $customID) { $customIDs[$customID] = array(); } require_once 'CRM/Core/BAO/CustomQuery.php'; $customQuery = new CRM_Core_BAO_CustomQuery($customIDs); $customQuery->query(); $options = $customQuery->_options; foreach ($relCustomData as $id => $customdatavalue) { if (in_array($relationkey, $customdatavalue)) { $customkey = "custom_{$id}"; if ($val['result']) { foreach ($val['result'] as $k => $v) { $cid = $v['id']; $param = array('entityID' => $cid, $customkey => 1); //Get custom data values $getCustomValueRel = CRM_Core_BAO_CustomValueTable::getValues($param); if (!array_key_exists('error_message', $getCustomValueRel)) { $customData = CRM_Core_BAO_CustomField::getDisplayValue($getCustomValueRel[$customkey], $id, $options); } else { $customData = ''; } if ($customData) { break; } } } } } if (is_array($relationvalue)) { if (array_key_exists('location', $value)) { foreach ($value['location'] as $columnkey => $columnvalue) { foreach ($columnvalue as $colkey => $colvalue) { list($serviceProvider, $serviceProviderID) = explode('-', $colkey); if (in_array($serviceProvider, array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'state_province', 'country'))) { $serviceProvider = 'address'; } $output = null; foreach ((array) $data->{$serviceProvider} as $datakey => $datavalue) { if ($columnkey == 'Primary') { $columnkey = $locationTypes[$datavalue['location_type_id']]; } if ($locationTypes[$datavalue['location_type_id']] == $columnkey) { if (array_key_exists($colkey, $datavalue)) { $output = $datavalue[$colkey]; } else { if ($colkey == 'country') { $countryId = $datavalue['country_id']; if ($countryId) { require_once 'CRM/Core/PseudoConstant.php'; $country =& CRM_Core_PseudoConstant::country($countryId); } else { $country = ''; } $output = $country; } else { if ($colkey == 'state_province') { $stateProvinceId = $datavalue['state_province_id']; if ($stateProvinceId) { $stateProvince =& CRM_Core_PseudoConstant::stateProvince($stateProvinceId); } else { $stateProvince = ''; } $output = $stateProvince; } else { if (is_numeric($serviceProviderID)) { if ($serviceProvider == 'phone') { if (isset($datavalue['phone'])) { $output = $datavalue['phone']; } else { $output = ''; } } else { if ($serviceProvider == 'im') { if (isset($datavalue['name'])) { $output = $datavalue['name']; } else { $output = ''; } } } } else { if ($datavalue['location_type_id']) { if ($colkey == 'im') { $output = $datavalue['name']; } else { $output = $datavalue[$colkey]; } } else { $output = ''; } } } } } } } if ($is_valid) { $row[] = $output; } else { $row[] = ''; } } } } } else { if ($cfID = CRM_Core_BAO_CustomField::getKeyID($relationkey) && $is_valid) { $row[] = $custom_data; } else { if ($query->_fields[$relationkey]['name'] && $is_valid) { if ($query->_fields[$relationkey]['name'] == 'gender') { $getGenders =& CRM_Core_PseudoConstant::gender(); $gender = array_search($data->gender_id, array_flip($getGenders)); $row[] = $gender; } else { if ($query->_fields[$relationkey]['name'] == 'greeting_type') { $getgreeting =& CRM_Core_PseudoConstant::greeting(); $greeting = array_search($data->greeting_type_id, array_flip($getgreeting)); $row[] = $greeting; } else { $colValue = $query->_fields[$relationkey]['name']; $row[] = $data->{$colValue}; } } } else { if ($customData && $is_valid) { $row[] = $customData; } else { $row[] = ''; } } } } } } else { if (isset($fieldValue) && $fieldValue != '') { //check for custom data if ($cfID = CRM_Core_BAO_CustomField::getKeyID($field)) { $row[$field] = CRM_Core_BAO_CustomField::getDisplayValue($fieldValue, $cfID, $query->_options); } else { if (array_key_exists($field, $multipleSelectFields)) { //option group fixes $paramsNew = array($field => $fieldValue); if ($field == 'test_tutoring') { $name = array($field => array('newName' => $field, 'groupName' => 'test')); } else { if (substr($field, 0, 4) == 'cmr_') { //for readers group $name = array($field => array('newName' => $field, 'groupName' => substr($field, 0, -3))); } else { $name = array($field => array('newName' => $field, 'groupName' => $field)); } } CRM_Core_OptionGroup::lookupValues($paramsNew, $name, false); $row[$field] = $paramsNew[$field]; } else { if (in_array($field, array('email_greeting', 'postal_greeting', 'addressee'))) { //special case for greeting replacement $fldValue = "{$field}_display"; $row[$field] = $dao->{$fldValue}; } else { //normal fields $row[$field] = $fieldValue; } } } } else { // if field is empty or null $row[$field] = ''; } } } } } } } //build header only once $setHeader = false; // add payment headers if required if ($addPaymentHeader && $paymentFields) { $headerRows = array_merge($headerRows, $paymentHeaders); $addPaymentHeader = false; } // add payment related information if ($paymentFields && isset($paymentDetails[$row[$paymentTableId]])) { $row = array_merge($row, $paymentDetails[$row[$paymentTableId]]); } //remove organization name for individuals if it is set for current employer if (CRM_Utils_Array::value('contact_type', $row) && $row['contact_type'] == 'Individual') { $row['organization_name'] = ''; } // add component info $componentDetails[] = $row; } require_once 'CRM/Core/Report/Excel.php'; CRM_Core_Report_Excel::writeCSVFile(self::getExportFileName('csv', $exportMode), $headerRows, $componentDetails); exit; }
function setDefaultValues() { if ($this->_cdType) { return CRM_Custom_Form_CustomData::setDefaultValues($this); } $defaults = $this->_values; //set defaults for pledge payment. if ($this->_ppID) { $defaults['total_amount'] = CRM_Utils_Array::value('scheduled_amount', $this->_pledgeValues['pledgePayment']); $defaults['honor_type_id'] = CRM_Utils_Array::value('honor_type_id', $this->_pledgeValues); $defaults['honor_contact_id'] = CRM_Utils_Array::value('honor_contact_id', $this->_pledgeValues); $defaults['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_pledgeValues); $defaults['currency'] = CRM_Utils_Array::value('currency', $this->_pledgeValues); $defaults['option_type'] = 1; } $fields = array(); if ($this->_action & CRM_Core_Action::DELETE) { return $defaults; } // set soft credit defaults CRM_Contribute_Form_SoftCredit::setDefaultValues($defaults, $this); if ($this->_mode) { $config = CRM_Core_Config::singleton(); // set default country from config if no country set if (!CRM_Utils_Array::value("billing_country_id-{$this->_bltID}", $defaults)) { $defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry; } if (!CRM_Utils_Array::value("billing_state_province_id-{$this->_bltID}", $defaults)) { $defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince; } $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID); $defaults = array_merge($defaults, $billingDefaults); // now fix all state country selectors, set correct state based on country CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults); } if ($this->_id) { $this->_contactID = $defaults['contact_id']; } // Set $newCredit variable in template to control whether link to credit card mode is included CRM_Core_Payment::allowBackofficeCreditCard($this); // fix the display of the monetary value, CRM-4038 if (isset($defaults['total_amount'])) { $defaults['total_amount'] = CRM_Utils_Money::format($defaults['total_amount'], NULL, '%a'); } if (isset($defaults['non_deductible_amount'])) { $defaults['non_deductible_amount'] = CRM_Utils_Money::format($defaults['non_deductible_amount'], NULL, '%a'); } if (isset($defaults['fee_amount'])) { $defaults['fee_amount'] = CRM_Utils_Money::format($defaults['fee_amount'], NULL, '%a'); } if (isset($defaults['net_amount'])) { $defaults['net_amount'] = CRM_Utils_Money::format($defaults['net_amount'], NULL, '%a'); } if ($this->_contributionType) { $defaults['financial_type_id'] = $this->_contributionType; } if (!CRM_Utils_Array::value('payment_instrument_id', $defaults)) { $defaults['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1')); } if (CRM_Utils_Array::value('is_test', $defaults)) { $this->assign('is_test', TRUE); } if (isset($defaults['honor_contact_id'])) { $honorDefault = $ids = array(); $this->_honorID = $defaults['honor_contact_id']; $honorType = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'honor_type_id'); $idParams = array('id' => $defaults['honor_contact_id'], 'contact_id' => $defaults['honor_contact_id']); CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault, $ids); $defaults['honor_prefix_id'] = CRM_Utils_Array::value('prefix_id', $honorDefault); $defaults['honor_first_name'] = CRM_Utils_Array::value('first_name', $honorDefault); $defaults['honor_last_name'] = CRM_Utils_Array::value('last_name', $honorDefault); $defaults['honor_email'] = CRM_Utils_Array::value('email', $honorDefault['email'][1]); $defaults['honor_type'] = $honorType[$defaults['honor_type_id']]; } $this->assign('showOption', TRUE); // for Premium section if ($this->_premiumID) { $this->assign('showOption', FALSE); $options = isset($this->_options[$this->_productDAO->product_id]) ? $this->_options[$this->_productDAO->product_id] : ""; if (!$options) { $this->assign('showOption', TRUE); } $options_key = CRM_Utils_Array::key($this->_productDAO->product_option, $options); if ($options_key) { $defaults['product_name'] = array($this->_productDAO->product_id, trim($options_key)); } else { $defaults['product_name'] = array($this->_productDAO->product_id); } if ($this->_productDAO->fulfilled_date) { list($defaults['fulfilled_date']) = CRM_Utils_Date::setDateDefaults($this->_productDAO->fulfilled_date); } } if (isset($this->userEmail)) { $this->assign('email', $this->userEmail); } if (CRM_Utils_Array::value('is_pay_later', $defaults)) { $this->assign('is_pay_later', TRUE); } $this->assign('contribution_status_id', CRM_Utils_Array::value('contribution_status_id', $defaults)); $dates = array('receive_date', 'receipt_date', 'cancel_date', 'thankyou_date'); foreach ($dates as $key) { if (CRM_Utils_Array::value($key, $defaults)) { list($defaults[$key], $defaults[$key . '_time']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value($key, $defaults), 'activityDateTime'); } } if (!$this->_id && !CRM_Utils_Array::value('receive_date', $defaults)) { list($defaults['receive_date'], $defaults['receive_date_time']) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime'); } $this->assign('receive_date', CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $defaults), CRM_Utils_Array::value('receive_date_time', $defaults))); $currency = CRM_Utils_Array::value('currency', $defaults); $this->assign('currency', $currency); // Hack to get currency info to the js layer. CRM-11440 CRM_Utils_Money::format(1); $this->assign('currencySymbol', CRM_Utils_Array::value($currency, CRM_Utils_Money::$_currencySymbols)); $this->assign('totalAmount', CRM_Utils_Array::value('total_amount', $defaults)); //inherit campaign from pledge. if ($this->_ppID && CRM_Utils_Array::value('campaign_id', $this->_pledgeValues)) { $defaults['campaign_id'] = $this->_pledgeValues['campaign_id']; } $this->_defaults = $defaults; return $defaults; }
function setDefaultValues() { if ($this->_cdType) { return CRM_Custom_Form_CustomData::setDefaultValues($this); } $defaults = $this->_values; //set defaults for pledge payment. if ($this->_ppID) { $defaults['total_amount'] = CRM_Utils_Array::value('scheduled_amount', $this->_pledgeValues['pledgePayment']); $defaults['honor_type_id'] = CRM_Utils_Array::value('honor_type_id', $this->_pledgeValues); $defaults['honor_contact_id'] = CRM_Utils_Array::value('honor_contact_id', $this->_pledgeValues); $defaults['contribution_type_id'] = CRM_Utils_Array::value('contribution_type_id', $this->_pledgeValues); } $fields = array(); if ($this->_action & CRM_Core_Action::DELETE) { return $defaults; } if ($this->_mode) { $billingFields = array(); foreach ($this->_fields as $name => $dontCare) { if (strpos($name, 'billing_') === 0) { $name = $idName = substr($name, 8); if (in_array($name, array("state_province_id-{$this->_bltID}", "country_id-{$this->_bltID}"))) { $name = str_replace('_id', '', $name); } $billingFields[$name] = "billing_" . $idName; } $fields[$name] = 1; } require_once "CRM/Core/BAO/UFGroup.php"; if ($this->_contactID) { CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $defaults); } foreach ($billingFields as $name => $billingName) { $defaults[$billingName] = $defaults[$name]; } } if ($this->_id) { $this->_contactID = $defaults['contact_id']; } else { list($defaults['receive_date']) = CRM_Utils_Date::setDateDefaults(); } require_once 'CRM/Utils/Money.php'; // fix the display of the monetary value, CRM-4038 if (isset($defaults['total_amount'])) { $defaults['total_amount'] = CRM_Utils_Money::format($defaults['total_amount'], null, '%a'); } if (isset($defaults['non_deductible_amount'])) { $defaults['non_deductible_amount'] = CRM_Utils_Money::format($defaults['non_deductible_amount'], null, '%a'); } if (isset($defaults['fee_amount'])) { $defaults['fee_amount'] = CRM_Utils_Money::format($defaults['fee_amount'], null, '%a'); } if (isset($defaults['net_amount'])) { $defaults['net_amount'] = CRM_Utils_Money::format($defaults['net_amount'], null, '%a'); } if ($this->_contributionType) { $defaults['contribution_type_id'] = $this->_contributionType; } if (CRM_Utils_Array::value('is_test', $defaults)) { $this->assign("is_test", true); } if (isset($defaults["honor_contact_id"])) { $honorDefault = array(); $ids = array(); $this->_honorID = $defaults["honor_contact_id"]; $honorType = CRM_Core_PseudoConstant::honor(); $idParams = array('id' => $defaults["honor_contact_id"], 'contact_id' => $defaults["honor_contact_id"]); CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault, $ids); $defaults["honor_prefix_id"] = $honorDefault["prefix_id"]; $defaults["honor_first_name"] = CRM_Utils_Array::value("first_name", $honorDefault); $defaults["honor_last_name"] = CRM_Utils_Array::value("last_name", $honorDefault); $defaults["honor_email"] = CRM_Utils_Array::value("email", $honorDefault["location"][1]["email"][1]); $defaults["honor_type"] = $honorType[$defaults["honor_type_id"]]; } $this->assign('showOption', true); // for Premium section if ($this->_premiumID) { $this->assign('showOption', false); $options = isset($this->_options[$this->_productDAO->product_id]) ? $this->_options[$this->_productDAO->product_id] : ""; if (!$options) { $this->assign('showOption', true); } $options_key = CRM_Utils_Array::key($this->_productDAO->product_option, $options); if ($options_key) { $defaults['product_name'] = array($this->_productDAO->product_id, trim($options_key)); } else { $defaults['product_name'] = array($this->_productDAO->product_id); } list($defaults['fulfilled_date']) = CRM_Utils_Date::setDateDefaults($this->_productDAO->fulfilled_date); } if (isset($this->userEmail)) { $this->assign('email', $this->userEmail); } if (CRM_Utils_Array::value('is_pay_later', $defaults)) { $this->assign('is_pay_later', true); } $this->assign('contribution_status_id', CRM_Utils_Array::value('contribution_status_id', $defaults)); $dates = array('receive_date', 'receipt_date', 'cancel_date', 'thankyou_date'); foreach ($dates as $key) { if (CRM_Utils_Array::value($key, $defaults)) { list($defaults[$key]) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value($key, $defaults)); } } $this->assign('receive_date', CRM_Utils_Array::value('receive_date', $defaults)); $this->assign('currency', CRM_Utils_Array::value('currency', $defaults)); $this->assign('totalAmount', CRM_Utils_Array::value('total_amount', $defaults)); return $defaults; }
/** * Update a specified location with the provided property values. * * @param object $contact A valid Contact object (passed by reference). * @param string $location_id Valid (db-level) id for location to be updated. * @param Array $params Associative array of property name/value pairs to be updated * * @return Location object with updated property values * * @access public * */ function crm_update_location(&$contact, $location_id, $params) { _crm_initialize(); if (!isset($contact->id)) { return _crm_error('$contact is not valid contact datatype'); } $locationId = (int) $location_id; if ($locationId == 0) { return _crm_error('missing or invalid $location_id'); } // $locationNumber is the contact-level number of the location (1, 2, 3, etc.) $locationNumber = null; $locations =& crm_get_locations($contact); foreach ($locations as $locNumber => $locValue) { if ($locValue->id == $locationId) { $locationNumber = $locNumber; break; } } if (!$locationNumber) { return _crm_error('invalid $location_id'); } $values = array('contact_id' => $contact->id, 'location' => array($locationNumber => array())); $loc =& $values['location'][$locationNumber]; $loc['address'] = array(); require_once 'CRM/Core/DAO/Address.php'; $fields =& CRM_Core_DAO_Address::fields(); _crm_store_values($fields, $params, $loc['address']); //$ids = array( 'county', 'country_id', 'state_province_id', 'supplemental_address_1', 'supplemental_address_2', 'StateProvince.name' ); $ids = array('county', 'country_id', 'country', 'state_province_id', 'state_province', 'supplemental_address_1', 'supplemental_address_2', 'StateProvince.name', 'street_address'); foreach ($ids as $id) { if (array_key_exists($id, $params)) { $loc['address'][$id] = $params[$id]; } } if (is_numeric($loc['address']['state_province'])) { $loc['address']['state_province'] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($loc['address']['state_province']); } if (is_numeric($loc['address']['country'])) { $loc['address']['country'] = CRM_Core_PseudoConstant::countryIsoCode($loc['address']['country']); } if (array_key_exists('location_type_id', $params)) { $loc['location_type_id'] = $params['location_type_id']; } if (array_key_exists('location_type', $params)) { $locTypes =& CRM_Core_PseudoConstant::locationType(); $loc['location_type_id'] = CRM_Utils_Array::key($params['location_type'], $locTypes); } if (array_key_exists('name', $params)) { $loc['name'] = $params['name']; } if (array_key_exists('is_primary', $params)) { $loc['is_primary'] = (int) $params['is_primary']; } $loc['id'] = $locationId; $blocks = array('Email', 'Phone', 'IM'); foreach ($blocks as $block) { $name = strtolower($block); $loc[$name] = array(); if ($params[$name]) { $count = 1; foreach ($params[$name] as $val) { CRM_Core_DAO::storeValues($val, $loc[$name][$count++]); } } } $par = array('id' => $contact->id, 'contact_id' => $contact->id); $contact = CRM_Contact_BAO_Contact::retrieve($par, $defaults, $ids); CRM_Contact_BAO_Contact::resolveDefaults($values, true); $location = CRM_Core_BAO_Location::add($values, $ids, $locationNumber); return $location; }
/** * Function for validation * * @param array $params (ref.) an assoc array of name/value pairs * * @return mixed true or array of errors * @access public * @static */ function dataRule(&$params, &$files, &$options) { if (CRM_Utils_Array::value('_qf_Import_refresh', $_POST)) { return true; } $errors = array(); require_once 'CRM/Core/BAO/Domain.php'; $domain =& CRM_Core_BAO_Domain::getCurrentDomain(); $mailing = null; $session =& CRM_Core_Session::singleton(); $values = array('contact_id' => $session->get('userID')); $contact = array(); $ids = array(); CRM_Contact_BAO_Contact::retrieve($values, $contact, $id); $verp = array_flip(array('optOut', 'reply', 'unsubscribe', 'owner')); foreach ($verp as $key => $value) { $verp[$key]++; } $urls = array_flip(array('forward')); foreach ($urls as $key => $value) { $urls[$key]++; } require_once 'CRM/Mailing/BAO/Component.php'; $header =& new CRM_Mailing_BAO_Component(); $header->id = $params['header_id']; $header->find(true); $footer =& new CRM_Mailing_BAO_Component(); $footer->id = $params['footer_id']; $footer->find(true); list($headerBody['htmlFile'], $headerBody['textFile']) = array($header->body_html, $header->body_text); list($footerBody['htmlFile'], $footerBody['textFile']) = array($footer->body_html, $footer->body_text); require_once 'CRM/Utils/Token.php'; if (!file_exists($files['textFile']['tmp_name'])) { $errors['textFile'] = ts('Please provide at least the text message.'); } foreach (array('textFile', 'htmlFile') as $file) { if (!file_exists($files[$file]['tmp_name'])) { continue; } $str = file_get_contents($files[$file]['tmp_name']); $name = $files[$file]['name']; /* append header/footer */ $str = $headerBody[$file] . $str . $footerBody[$file]; $dataErrors = array(); /* First look for missing tokens */ $err = CRM_Utils_Token::requiredTokens($str); if ($err !== true) { foreach ($err as $token => $desc) { $dataErrors[] = '<li>' . ts('Missing required token') . ' {' . $token . "}: {$desc}</li>"; } } /* Do a full token replacement on a dummy verp, the current contact * and domain. */ $str = CRM_Utils_Token::replaceDomainTokens($str, $domain); $str = CRM_Utils_Token::replaceMailingTokens($str, $mailing); $str = CRM_Utils_Token::replaceActionTokens($str, $verp, $urls); $str = CRM_Utils_Token::replaceContactTokens($str, $contact); $unmatched = CRM_Utils_Token::unmatchedTokens($str); if (!empty($unmatched)) { foreach ($unmatched as $token) { $dataErrors[] = '<li>' . ts('Invalid token code') . ' {' . $token . '}</li>'; } } if (!empty($dataErrors)) { $errors[$file] = ts('The following errors were detected in %1:', array(1 => $name)) . ': <ul>' . implode('', $dataErrors) . '</ul>'; } } return empty($errors) ? true : $errors; }
function sendMail(&$input, &$ids, &$objects, &$values, $recur = false, $returnMessageText = false) { $contribution =& $objects['contribution']; $membership =& $objects['membership']; $participant =& $objects['participant']; $event =& $objects['event']; if (empty($values)) { $values = array(); if ($input['component'] == 'contribute') { require_once 'CRM/Contribute/BAO/ContributionPage.php'; if (isset($contribution->contribution_page_id)) { CRM_Contribute_BAO_ContributionPage::setValues($contribution->contribution_page_id, $values); } else { // Handle re-print receipt for offline contributions (call from PDF.php - no contribution_page_id) $values['is_email_receipt'] = 1; $values['title'] = 'Contribution'; } } else { // event $eventParams = array('id' => $objects['event']->id); $values['event'] = array(); require_once 'CRM/Event/BAO/Event.php'; CRM_Event_BAO_Event::retrieve($eventParams, $values['event']); $eventParams = array('id' => $objects['event']->id); $values['event'] = array(); require_once 'CRM/Event/BAO/Event.php'; CRM_Event_BAO_Event::retrieve($eventParams, $values['event']); //get location details $locationParams = array('entity_id' => $objects['event']->id, 'entity_table' => 'civicrm_event'); require_once 'CRM/Core/BAO/Location.php'; require_once 'CRM/Event/Form/ManageEvent/Location.php'; $values['location'] = CRM_Core_BAO_Location::getValues($locationParams); require_once 'CRM/Core/BAO/UFJoin.php'; $ufJoinParams = array('entity_table' => 'civicrm_event', 'entity_id' => $ids['event'], 'weight' => 1); $values['custom_pre_id'] = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams); $ufJoinParams['weight'] = 2; $values['custom_post_id'] = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams); } } $template =& CRM_Core_Smarty::singleton(); // CRM_Core_Error::debug('tpl',$template); //assign honor infomation to receiptmessage if ($honarID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contribution->id, 'honor_contact_id')) { $honorDefault = array(); $honorIds = array(); $honorIds['contribution'] = $contribution->id; $idParams = array('id' => $honarID, 'contact_id' => $honarID); require_once "CRM/Contact/BAO/Contact.php"; CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault, $honorIds); require_once "CRM/Core/PseudoConstant.php"; $honorType = CRM_Core_PseudoConstant::honor(); $prefix = CRM_Core_PseudoConstant::individualPrefix(); $template->assign('honor_block_is_active', 1); $template->assign('honor_prefix', $prefix[$honorDefault["prefix_id"]]); $template->assign('honor_first_name', CRM_Utils_Array::value("first_name", $honorDefault)); $template->assign('honor_last_name', CRM_Utils_Array::value("last_name", $honorDefault)); $template->assign('honor_email', CRM_Utils_Array::value("email", $honorDefault["email"][1])); $template->assign('honor_type', $honorType[$contribution->honor_type_id]); } require_once 'CRM/Contribute/DAO/ContributionProduct.php'; $dao =& new CRM_Contribute_DAO_ContributionProduct(); $dao->contribution_id = $contribution->id; if ($dao->find(true)) { $premiumId = $dao->product_id; $template->assign('option', $dao->product_option); require_once 'CRM/Contribute/DAO/Product.php'; $productDAO =& new CRM_Contribute_DAO_Product(); $productDAO->id = $premiumId; $productDAO->find(true); $template->assign('selectPremium', true); $template->assign('product_name', $productDAO->name); $template->assign('price', $productDAO->price); $template->assign('sku', $productDAO->sku); } // add the new contribution values if ($input['component'] == 'contribute') { $template->assign('title', $values['title']); $template->assign('amount', $input['amount']); //PCP Info require_once 'CRM/Contribute/DAO/ContributionSoft.php'; $softDAO =& new CRM_Contribute_DAO_ContributionSoft(); $softDAO->contribution_id = $contribution->id; if ($softDAO->find(true)) { $template->assign('pcpBlock', true); $template->assign('pcp_display_in_roll', $softDAO->pcp_display_in_roll); $template->assign('pcp_roll_nickname', $softDAO->pcp_roll_nickname); $template->assign('pcp_personal_note', $softDAO->pcp_personal_note); //assign the pcp page title for email subject require_once 'CRM/Contribute/DAO/PCP.php'; $pcpDAO =& new CRM_Contribute_DAO_PCP(); $pcpDAO->id = $softDAO->pcp_id; if ($pcpDAO->find(true)) { $template->assign('title', $pcpDAO->title); } } } else { $template->assign('title', $values['event']['title']); $template->assign('totalAmount', $input['amount']); } $template->assign('trxn_id', $contribution->trxn_id); $template->assign('receive_date', CRM_Utils_Date::mysqlToIso($contribution->receive_date)); $template->assign('contributeMode', 'notify'); $template->assign('action', $contribution->is_test ? 1024 : 1); $template->assign('receipt_text', CRM_Utils_Array::value('receipt_text', $values)); $template->assign('is_monetary', 1); $template->assign('is_recur', $recur); if ($recur) { require_once 'CRM/Core/Payment.php'; $paymentObject =& CRM_Core_Payment::singleton($contribution->is_test ? 'test' : 'live', 'Contribute', $objects['paymentProcessor']); $url = $paymentObject->cancelSubscriptionURL(); $template->assign('cancelSubscriptionUrl', $url); if ($objects['paymentProcessor']['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM) { //direct mode showing billing block, so use directIPN for temporary $template->assign('contributeMode', 'directIPN'); } } require_once 'CRM/Utils/Address.php'; $template->assign('address', CRM_Utils_Address::format($input)); if ($input['component'] == 'event') { require_once 'CRM/Core/OptionGroup.php'; $participant_role = CRM_Core_OptionGroup::values('participant_role'); $values['event']['participant_role'] = $participant_role[$participant->role_id]; $template->assign('event', $values['event']); $template->assign('location', $values['location']); $template->assign('customPre', $values['custom_pre_id']); $template->assign('customPost', $values['custom_post_id']); $isTest = false; if ($participant->is_test) { $isTest = true; } $values['params'] = array(); require_once "CRM/Event/BAO/Event.php"; //to get email of primary participant. $primaryEmail = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $participant->contact_id, 'email', 'contact_id'); $primaryAmount[] = array('label' => $participant->fee_level . ' - ' . $primaryEmail, 'amount' => $participant->fee_amount); //build an array of cId/pId of participants $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($participant->id, null, $ids['contact'], $isTest, true); unset($additionalIDs[$participant->id]); //send receipt to additional participant if exists if (count($additionalIDs)) { $template->assign('isPrimary', 0); $template->assign('customProfile', null); //set additionalParticipant true $values['params']['additionalParticipant'] = true; foreach ($additionalIDs as $pId => $cId) { $amount = array(); //to change the status pending to completed $additional =& new CRM_Event_DAO_Participant(); $additional->id = $pId; $additional->contact_id = $cId; $additional->find(true); $additional->register_date = $participant->register_date; $additional->status_id = 1; $additionalParticipantInfo = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $additional->contact_id, 'email', 'contact_id'); //if additional participant dont have email //use display name. if (!$additionalParticipantInfo) { require_once "CRM/Contact/BAO/Contact.php"; $additionalParticipantInfo = CRM_Contact_BAO_Contact::displayName($additional->contact_id); } $amount[0] = array('label' => $additional->fee_level, 'amount' => $additional->fee_amount); $primaryAmount[] = array('label' => $additional->fee_level . ' - ' . $additionalParticipantInfo, 'amount' => $additional->fee_amount); $additional->save(); $additional->free(); $template->assign('amount', $amount); CRM_Event_BAO_Event::sendMail($cId, $values, $pId, $isTest, $returnMessageText); } } //build an array of custom profile and assigning it to template $customProfile = CRM_Event_BAO_Event::buildCustomProfile($participant->id, $values, null, $isTest); if (count($customProfile)) { $template->assign('customProfile', $customProfile); } // for primary contact $values['params']['additionalParticipant'] = false; $template->assign('isPrimary', 1); $template->assign('amount', $primaryAmount); // carry paylater, since we did not created billing, // so need to pull email from primary location, CRM-4395 $values['params']['is_pay_later'] = $participant->is_pay_later; return CRM_Event_BAO_Event::sendMail($ids['contact'], $values, $participant->id, $isTest, $returnMessageText); } else { if ($membership) { $values['membership_id'] = $membership->id; // need to set the membership values here $template->assign('membership_assign', 1); require_once 'CRM/Member/PseudoConstant.php'; $template->assign('membership_name', CRM_Member_PseudoConstant::membershipType($membership->membership_type_id)); $template->assign('mem_start_date', $membership->start_date); $template->assign('mem_end_date', $membership->end_date); // if separate payment there are two contributions recorded and the // admin will need to send a receipt for each of them separately. // we dont link the two in the db (but can potentially infer it if needed) $template->assign('is_separate_payment', 0); } $values['contribution_id'] = $contribution->id; if (CRM_Utils_Array::value('related_contact', $ids)) { $values['related_contact'] = $ids['related_contact']; if (isset($ids['onbehalf_dupe_alert'])) { $values['onbehalf_dupe_alert'] = $ids['onbehalf_dupe_alert']; } require_once 'CRM/Core/BAO/Address.php'; $entityBlock = array('contact_id' => $ids['contact'], 'location_type_id' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_LocationType', 'Main', 'id', 'name')); $address = CRM_Core_BAO_Address::getValues($entityBlock); $template->assign('onBehalfAddress', $address[$entityBlock['location_type_id']]['display']); } $isTest = false; if ($contribution->is_test) { $isTest = true; } // CRM_Core_Error::debug('val',$values); return CRM_Contribute_BAO_ContributionPage::sendMail($ids['contact'], $values, $isTest, $returnMessageText); } }
/** * This function sets the default values for the form. * the default values are retrieved from the database * * @access public * * @return None */ function setDefaultValues() { $defaults = $this->_values; $fields = array(); if ($this->_action & CRM_Core_Action::DELETE) { return $defaults; } if (CRM_Utils_Array::value('is_test', $defaults)) { $this->assign('is_test', TRUE); } if ($this->_id) { $startDate = CRM_Utils_Array::value('start_date', $this->_values); $createDate = CRM_Utils_Array::value('create_date', $this->_values); list($defaults['start_date']) = CRM_Utils_Date::setDateDefaults($startDate); list($defaults['create_date']) = CRM_Utils_Date::setDateDefaults($createDate); if ($ackDate = CRM_Utils_Array::value('acknowledge_date', $this->_values)) { list($defaults['acknowledge_date']) = CRM_Utils_Date::setDateDefaults($ackDate); } //check is this pledge pending // fix the display of the monetary value, CRM-4038 if ($this->_isPending) { $defaults['eachPaymentAmount'] = $this->_values['amount'] / $this->_values['installments']; $defaults['eachPaymentAmount'] = CRM_Utils_Money::format($defaults['eachPaymentAmount'], NULL, '%a'); } else { $this->assign('start_date', $startDate); $this->assign('create_date', $createDate); } // fix the display of the monetary value, CRM-4038 if (isset($this->_values['amount'])) { $defaults['amount'] = CRM_Utils_Money::format($this->_values['amount'], NULL, '%a'); } $this->assign('amount', $this->_values['amount']); $this->assign('installments', $defaults['installments']); } else { //default values. list($now) = CRM_Utils_Date::setDateDefaults(); $defaults['create_date'] = $now; $defaults['start_date'] = $now; $defaults['installments'] = 12; $defaults['frequency_interval'] = 1; $defaults['frequency_day'] = 1; $defaults['initial_reminder_day'] = 5; $defaults['max_reminders'] = 1; $defaults['additional_reminder_day'] = 5; $defaults['frequency_unit'] = array_search('month', $this->_freqUnits); $defaults['contribution_type_id'] = array_search('Donation', CRM_Contribute_PseudoConstant::contributionType()); } $pledgeStatus = CRM_Contribute_PseudoConstant::contributionStatus(); $pledgeStatusNames = CRM_Core_OptionGroup::values('contribution_status', FALSE, FALSE, FALSE, NULL, 'name', TRUE); // get default status label (pending) $defaultPledgeStatus = CRM_Utils_Array::value(array_search('Pending', $pledgeStatusNames), $pledgeStatus); //assign status. $this->assign('status', CRM_Utils_Array::value(CRM_Utils_Array::value('status_id', $this->_values), $pledgeStatus, $defaultPledgeStatus)); //honoree contact. if ($this->_honorID) { $honorDefault = array(); $idParams = array('contact_id' => $this->_honorID); CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault); $honorType = CRM_Core_PseudoConstant::honor(); $defaults['honor_prefix_id'] = $honorDefault['prefix_id']; $defaults['honor_first_name'] = CRM_Utils_Array::value('first_name', $honorDefault); $defaults['honor_last_name'] = CRM_Utils_Array::value('last_name', $honorDefault); $defaults['honor_email'] = CRM_Utils_Array::value('email', $honorDefault['email'][1]); $defaults['honor_type'] = $honorType[$defaults['honor_type_id']]; } if (isset($this->userEmail)) { $this->assign('email', $this->userEmail); } // custom data set defaults $defaults += CRM_Custom_Form_CustomData::setDefaultValues($this); return $defaults; }
/** * This function sets the default values for the form. * the default values are retrieved from the database * * @access public * @return None */ function setDefaultValues() { $defaults = $this->_values; $fields = array(); if ($this->_action & CRM_Core_Action::DELETE) { return $defaults; } if (CRM_Utils_Array::value('is_test', $defaults)) { $this->assign("is_test", true); } if ($this->_id) { $startDate = CRM_Utils_Array::value('start_date', $this->_values); $createDate = CRM_Utils_Array::value('create_date', $this->_values); list($defaults['start_date']) = CRM_Utils_Date::setDateDefaults($startDate); list($defaults['create_date']) = CRM_Utils_Date::setDateDefaults($createDate); if ($this->_values['acknowledge_date']) { list($defaults['acknowledge_date']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value('acknowledge_date', $this->_values)); } //check is this pledge pending // fix the display of the monetary value, CRM-4038 require_once 'CRM/Utils/Money.php'; if ($this->_isPending) { $defaults['eachPaymentAmount'] = $this->_values['amount'] / $this->_values['installments']; $defaults['eachPaymentAmount'] = CRM_Utils_Money::format($defaults['eachPaymentAmount'], null, '%a'); } else { $this->assign('start_date', $startDate); $this->assign('create_date', $createDate); } // fix the display of the monetary value, CRM-4038 if (isset($this->_values['amount'])) { $defaults['amount'] = CRM_Utils_Money::format($this->_values['amount'], null, '%a'); } } else { //default values. list($now) = CRM_Utils_Date::setDateDefaults(); $defaults['create_date'] = $now; $defaults['start_date'] = $now; $defaults['installments'] = 12; $defaults['frequency_interval'] = 1; $defaults['frequency_day'] = 1; $defaults['initial_reminder_day'] = 5; $defaults['max_reminders'] = 1; $defaults['additional_reminder_day'] = 5; $defaults['frequency_unit'] = array_search('monthly', $this->_freqUnits); $defaults['contribution_type_id'] = array_search('Donation', CRM_Contribute_PseudoConstant::contributionType()); } //assign status. $this->assign('status', CRM_Utils_Array::value(CRM_Utils_Array::value('status_id', $this->_values), CRM_Contribute_PseudoConstant::contributionStatus(), 'Pending')); //honoree contact. if ($this->_honorID) { require_once 'CRM/Contact/BAO/Contact.php'; $honorDefault = array(); $idParams = array('contact_id' => $this->_honorID); CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault, $ids); $honorType = CRM_Core_PseudoConstant::honor(); $defaults["honor_prefix_id"] = $honorDefault["prefix_id"]; $defaults["honor_first_name"] = CRM_Utils_Array::value("first_name", $honorDefault); $defaults["honor_last_name"] = CRM_Utils_Array::value("last_name", $honorDefault); $defaults["honor_email"] = CRM_Utils_Array::value("email", $honorDefault["location"][1]["email"][1]); $defaults["honor_type"] = $honorType[$defaults["honor_type_id"]]; } $this->assign('email', $this->userEmail); // custom data set defaults $defaults += CRM_Custom_Form_Customdata::setDefaultValues($this); return $defaults; }
/** * static function to find players on other teams for any game */ public static function OtherTeams($teamID, $playerID) { $tournamentName = "2016"; // @todo Tournament::currentTournamentName(); $params = array('id' => $playerID); $player = CRM_Contact_BAO_Contact::retrieve($params, $defaults); $playerName = $player->sort_name; $team = Team::getTeam($teamID, $values); $team->otherTeamGamePlayerMessages('E', self::$_E, $playerID, $playerName, $tournamentName, $messages); $team->otherTeamGamePlayerMessages('O', self::$_O, $playerID, $playerName, $tournamentName, $messages); $team->otherTeamGamePlayerMessages('L', self::$_L, $playerID, $playerName, $tournamentName, $messages); $team->otherTeamGamePlayerMessages('P', self::$_P, $playerID, $playerName, $tournamentName, $messages); $team->otherTeamGamePlayerMessages('M', self::$_M, $playerID, $playerName, $tournamentName, $messages); $team->otherTeamGamePlayerMessages('A', self::$_A, $playerID, $playerName, $tournamentName, $messages); $team->otherTeamGamePlayerMessages('W', self::$_W, $playerID, $playerName, $tournamentName, $messages); return $messages; }
/** * View summary details of a contact * * @return void * @access public */ function view() { $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId); $session->pushUserContext($url); $params = array(); $defaults = array(); $ids = array(); $params['id'] = $params['contact_id'] = $this->_contactId; $params['noRelationships'] = $params['noNotes'] = $params['noGroups'] = true; $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, true); $communicationType = array('phone' => array('type' => 'phoneType', 'id' => 'phone_type'), 'im' => array('type' => 'IMProvider', 'id' => 'provider'), 'website' => array('type' => 'websiteType', 'id' => 'website_type'), 'address' => array('skip' => true, 'customData' => 1), 'email' => array('skip' => true), 'openid' => array('skip' => true)); foreach ($communicationType as $key => $value) { if (CRM_Utils_Array::value($key, $defaults)) { foreach ($defaults[$key] as &$val) { CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::locationType(), false); if (!CRM_Utils_Array::value('skip', $value)) { eval('$pseudoConst = CRM_Core_PseudoConstant::' . $value['type'] . '( );'); CRM_Utils_Array::lookupValue($val, $value['id'], $pseudoConst, false); } } if (isset($value['customData'])) { foreach ($defaults[$key] as $blockId => $blockVal) { $groupTree = CRM_Core_BAO_CustomGroup::getTree(ucfirst($key), $this, $blockVal['id']); // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var. $defaults[$key][$blockId]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, false, null, "dnc_"); } // reset template variable since that won't be of any use, and could be misleading $this->assign("dnc_viewCustomData", null); } } } if (CRM_Utils_Array::value('gender_id', $defaults)) { $gender = CRM_Core_PseudoConstant::gender(); $defaults['gender_display'] = $gender[CRM_Utils_Array::value('gender_id', $defaults)]; } // to make contact type label available in the template - $contactType = array_key_exists('contact_sub_type', $defaults) ? $defaults['contact_sub_type'] : $defaults['contact_type']; $defaults['contact_type_label'] = CRM_Contact_BAO_ContactType::contactTypePairs(true, $contactType); // get contact tags require_once 'CRM/Core/BAO/EntityTag.php'; $contactTags = CRM_Core_BAO_EntityTag::getContactTags($this->_contactId); if (!empty($contactTags)) { $defaults['contactTag'] = implode(', ', $contactTags); } $defaults['privacy_values'] = CRM_Core_SelectValues::privacy(); //Show blocks only if they are visible in edit form require_once 'CRM/Core/BAO/Preferences.php'; $this->_editOptions = CRM_Core_BAO_Preferences::valueOptions('contact_edit_options'); $configItems = array('CommBlock' => 'Communication Preferences', 'Demographics' => 'Demographics', 'TagsAndGroups' => 'Tags and Groups', 'Notes' => 'Notes'); foreach ($configItems as $c => $t) { $varName = '_show' . $c; $this->{$varName} = CRM_Utils_Array::value($c, $this->_editOptions); $this->assign(substr($varName, 1), $this->{$varName}); } // get contact name of shared contact names $sharedAddresses = array(); $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($defaults['address']); foreach ($defaults['address'] as $key => $addressValue) { if (CRM_Utils_Array::value('master_id', $addressValue) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) { $sharedAddresses[$key]['shared_address_display'] = array('address' => $addressValue['display'], 'name' => $shareAddressContactNames[$addressValue['master_id']]['name']); } } $this->assign('sharedAddresses', $sharedAddresses); //get the current employer name if (CRM_Utils_Array::value('contact_type', $defaults) == 'Individual') { if ($contact->employer_id && $contact->organization_name) { $defaults['current_employer'] = $contact->organization_name; $defaults['current_employer_id'] = $contact->employer_id; } //for birthdate format with respect to birth format set $this->assign('birthDateViewFormat', CRM_Utils_Array::value('qfMapping', CRM_Utils_Date::checkBirthDateFormat())); } $this->assign($defaults); // also assign the last modifed details require_once 'CRM/Core/BAO/Log.php'; $lastModified =& CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact'); $this->assign_by_ref('lastModified', $lastModified); $allTabs = array(); $weight = 10; $this->_viewOptions = CRM_Core_BAO_Preferences::valueOptions('contact_view_options', true); $changeLog = $this->_viewOptions['log']; $this->assign_by_ref('changeLog', $changeLog); require_once 'CRM/Core/Component.php'; $components = CRM_Core_Component::getEnabledComponents(); foreach ($components as $name => $component) { if (CRM_Utils_Array::value($name, $this->_viewOptions) && CRM_Core_Permission::access($component->name)) { $elem = $component->registerTab(); // FIXME: not very elegant, probably needs better approach // allow explicit id, if not defined, use keyword instead if (array_key_exists('id', $elem)) { $i = $elem['id']; } else { $i = $component->getKeyword(); } $u = $elem['url']; //appending isTest to url for test soft credit CRM-3891. //FIXME: hack ajax url. $q = "reset=1&snippet=1&force=1&cid={$this->_contactId}"; if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) { $q = $q . "&isTest=1"; } $allTabs[] = array('id' => $i, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$u}", $q), 'title' => $elem['title'], 'weight' => $elem['weight'], 'count' => CRM_Contact_BAO_Contact::getCountComponent($u, $this->_contactId)); // make sure to get maximum weight, rest of tabs go after // FIXME: not very elegant again if ($weight < $elem['weight']) { $weight = $elem['weight']; } } } $rest = array('activity' => ts('Activities'), 'case' => ts('Cases'), 'rel' => ts('Relationships'), 'group' => ts('Groups'), 'note' => ts('Notes'), 'tag' => ts('Tags'), 'log' => ts('Change Log')); $config = CRM_Core_Config::singleton(); if (isset($config->sunlight) && $config->sunlight) { $title = ts('Elected Officials'); $rest['sunlight'] = $title; $this->_viewOptions[$title] = true; } foreach ($rest as $k => $v) { if (CRM_Utils_Array::value($k, $this->_viewOptions)) { $allTabs[] = array('id' => $k, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$k}", "reset=1&snippet=1&cid={$this->_contactId}"), 'title' => $v, 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($k, $this->_contactId)); $weight += 10; } } // now add all the custom tabs $entityType = $this->get('contactType'); $activeGroups = CRM_Core_BAO_CustomGroup::getActiveGroups($entityType, 'civicrm/contact/view/cd', $this->_contactId); foreach ($activeGroups as $group) { $id = "custom_{$group['id']}"; $allTabs[] = array('id' => $id, 'url' => CRM_Utils_System::url($group['path'], $group['query'] . "&snippet=1&selectedChild={$id}"), 'title' => $group['title'], 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $group['table_name'])); $weight += 10; } // see if any other modules want to add any tabs require_once 'CRM/Utils/Hook.php'; CRM_Utils_Hook::tabs($allTabs, $this->_contactId); // now sort the tabs based on weight require_once 'CRM/Utils/Sort.php'; usort($allTabs, array('CRM_Utils_Sort', 'cmpFunc')); $this->assign('allTabs', $allTabs); $selectedChild = CRM_Utils_Request::retrieve('selectedChild', 'String', $this, false, 'summary'); $this->assign('selectedChild', $selectedChild); // hook for contact summary require_once 'CRM/Utils/Hook.php'; $contentPlacement = CRM_Utils_Hook::SUMMARY_BELOW; // ignored but needed to prevent warnings CRM_Utils_Hook::summary($this->_contactId, $content, $contentPlacement); if ($content) { $this->assign_by_ref('hookContent', $content); $this->assign('hookContentPlacement', $contentPlacement); } }
/** * Heart of the viewing process. The runner gets all the meta data for * the contact and calls the appropriate type of page to view. * * @return void * @access public * */ function preProcess() { parent::preProcess(); // we need to retrieve privacy preferences // to (un)display the 'Send an Email' link $params = array(); $defaults = array(); $ids = array(); $params['id'] = $params['contact_id'] = $this->_contactId; CRM_Contact_BAO_Contact::retrieve($params, $defaults, $ids); CRM_Contact_BAO_Contact::resolveDefaults($defaults); $this->assign($defaults); // also create the form element for the activity links box $controller =& new CRM_Core_Controller_Simple('CRM_Activity_Form_ActivityLinks', ts('Activity Links'), null); $controller->setEmbedded(true); $controller->run(); }
/** * build all the data structures needed to build the form * * @return void * @access public */ function preProcess() { $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add'); $this->_dedupeButtonName = $this->getButtonName('refresh', 'dedupe'); $this->_duplicateButtonName = $this->getButtonName('upload', 'duplicate'); $session = CRM_Core_Session::singleton(); if ($this->_action == CRM_Core_Action::ADD) { // check for add contacts permissions if (!CRM_Core_Permission::check('add contacts')) { CRM_Utils_System::permissionDenied(); CRM_Utils_System::civiExit(); } $this->_contactType = CRM_Utils_Request::retrieve('ct', 'String', $this, TRUE, NULL, 'REQUEST'); if (!in_array($this->_contactType, array('Individual', 'Household', 'Organization'))) { CRM_Core_Error::statusBounce(ts('Could not get a contact id and/or contact type')); } $this->_isContactSubType = FALSE; if ($this->_contactSubType = CRM_Utils_Request::retrieve('cst', 'String', $this)) { $this->_isContactSubType = TRUE; } if ($this->_contactSubType && !CRM_Contact_BAO_ContactType::isExtendsContactType($this->_contactSubType, $this->_contactType, TRUE)) { CRM_Core_Error::statusBounce(ts("Could not get a valid contact subtype for contact type '%1'", array(1 => $this->_contactType))); } $this->_gid = CRM_Utils_Request::retrieve('gid', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET'); $this->_tid = CRM_Utils_Request::retrieve('tid', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET'); $typeLabel = CRM_Contact_BAO_ContactType::contactTypePairs(TRUE, $this->_contactSubType ? $this->_contactSubType : $this->_contactType); $typeLabel = implode(' / ', $typeLabel); CRM_Utils_System::setTitle(ts('New %1', array(1 => $typeLabel))); $session->pushUserContext(CRM_Utils_System::url('civicrm/dashboard', 'reset=1')); $this->_contactId = NULL; } else { //update mode if (!$this->_contactId) { $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); } if ($this->_contactId) { $defaults = array(); $params = array('id' => $this->_contactId); $returnProperities = array('id', 'contact_type', 'contact_sub_type'); CRM_Core_DAO::commonRetrieve('CRM_Contact_DAO_Contact', $params, $defaults, $returnProperities); if (!CRM_Utils_Array::value('id', $defaults)) { CRM_Core_Error::statusBounce(ts('A Contact with that ID does not exist: %1', array(1 => $this->_contactId))); } $this->_contactType = CRM_Utils_Array::value('contact_type', $defaults); $this->_contactSubType = CRM_Utils_Array::value('contact_sub_type', $defaults); // check for permissions $session = CRM_Core_Session::singleton(); if ($session->get('userID') != $this->_contactId && !CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) { CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to edit this contact.')); } list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_contactId); CRM_Utils_System::setTitle($displayName, $contactImage . ' ' . $displayName); $context = CRM_Utils_Request::retrieve('context', 'String', $this); $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); $urlParams = 'reset=1&cid=' . $this->_contactId; if ($context) { $urlParams .= "&context={$context}"; } if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&key={$qfKey}"; } $session->pushUserContext(CRM_Utils_System::url('civicrm/contact/view', $urlParams)); $values = $this->get('values'); // get contact values. if (!empty($values)) { $this->_values = $values; } else { $params = array('id' => $this->_contactId, 'contact_id' => $this->_contactId, 'noRelationships' => TRUE, 'noNotes' => TRUE, 'noGroups' => TRUE); $contact = CRM_Contact_BAO_Contact::retrieve($params, $this->_values, TRUE); $this->set('values', $this->_values); } } else { CRM_Core_Error::statusBounce(ts('Could not get a contact_id and/or contact_type')); } } // parse street address, CRM-5450 $this->_parseStreetAddress = $this->get('parseStreetAddress'); if (!isset($this->_parseStreetAddress)) { $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options'); $this->_parseStreetAddress = FALSE; if (CRM_Utils_Array::value('street_address', $addressOptions) && CRM_Utils_Array::value('street_address_parsing', $addressOptions)) { $this->_parseStreetAddress = TRUE; } $this->set('parseStreetAddress', $this->_parseStreetAddress); } $this->assign('parseStreetAddress', $this->_parseStreetAddress); $this->_editOptions = $this->get('contactEditOptions'); if (CRM_Utils_System::isNull($this->_editOptions)) { $this->_editOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_edit_options', TRUE, NULL, FALSE, 'name', TRUE, 'AND v.filter = 0'); $this->set('contactEditOptions', $this->_editOptions); } // build demographics only for Individual contact type if ($this->_contactType != 'Individual' && array_key_exists('Demographics', $this->_editOptions)) { unset($this->_editOptions['Demographics']); } // in update mode don't show notes if ($this->_contactId && array_key_exists('Notes', $this->_editOptions)) { unset($this->_editOptions['Notes']); } $this->assign('editOptions', $this->_editOptions); $this->assign('contactType', $this->_contactType); $this->assign('contactSubType', $this->_contactSubType); //build contact subtype form element, CRM-6864 $buildContactSubType = TRUE; if ($this->_contactSubType && $this->_action & CRM_Core_Action::ADD) { $buildContactSubType = FALSE; } $this->assign('buildContactSubType', $buildContactSubType); // get the location blocks. $this->_blocks = $this->get('blocks'); if (CRM_Utils_System::isNull($this->_blocks)) { $this->_blocks = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_edit_options', TRUE, NULL, FALSE, 'name', TRUE, 'AND v.filter = 1'); $this->set('blocks', $this->_blocks); } $this->assign('blocks', $this->_blocks); // this is needed for custom data. $this->assign('entityID', $this->_contactId); // also keep the convention. $this->assign('contactId', $this->_contactId); // location blocks. CRM_Contact_Form_Location::preProcess($this); // execute preProcess dynamically by js else execute normal preProcess if (array_key_exists('CustomData', $this->_editOptions)) { if (CRM_Utils_Request::retrieve('type', 'String', CRM_Core_DAO::$_nullObject)) { CRM_Contact_Form_Edit_CustomData::preProcess($this); } else { $contactSubType = $this->_contactSubType; // need contact sub type to build related grouptree array during post process if (CRM_Utils_Array::value('contact_sub_type', $_POST)) { $contactSubType = $_POST['contact_sub_type']; } //only custom data has preprocess hence directly call it CRM_Custom_Form_CustomData::preProcess($this, NULL, $contactSubType, 1, $this->_contactType, $this->_contactId); } } }
/** * @return array */ public function setDefaultValues() { $defaults = parent::setDefaultValues(); $config = CRM_Core_Config::singleton(); $default_country = new CRM_Core_DAO_Country(); $default_country->iso_code = $config->defaultContactCountry(); $default_country->find(TRUE); $defaults["billing_country_id-{$this->_bltID}"] = $default_country->id; if (self::getContactID() && !self::is_administrator()) { $params = array('id' => self::getContactID()); $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults); foreach ($contact->email as $email) { if ($email['is_billing']) { $defaults["billing_contact_email"] = $email['email']; } } if (empty($defaults['billing_contact_email'])) { foreach ($contact->email as $email) { if ($email['is_primary']) { $defaults["billing_contact_email"] = $email['email']; } } } $defaults["billing_first_name"] = $contact->first_name; $defaults["billing_middle_name"] = $contact->middle_name; $defaults["billing_last_name"] = $contact->last_name; $billing_address = CRM_Event_Cart_BAO_MerParticipant::billing_address_from_contact($contact); if ($billing_address != NULL) { $defaults["billing_street_address-{$this->_bltID}"] = $billing_address['street_address']; $defaults["billing_city-{$this->_bltID}"] = $billing_address['city']; $defaults["billing_postal_code-{$this->_bltID}"] = $billing_address['postal_code']; $defaults["billing_state_province_id-{$this->_bltID}"] = $billing_address['state_province_id']; $defaults["billing_country_id-{$this->_bltID}"] = $billing_address['country_id']; } } $defaults["source"] = $this->description; return $defaults; }
/** * Function to actually build the form * * @return void * @access public */ public function buildQuickForm() { $params = array(); $params['id'] = $params['contact_id'] = $this->_contactId; $contact = CRM_Contact_BAO_Contact::retrieve($params, $this->_defaults); $countryID = ''; $stateID = ''; if (!empty($this->_defaults['address'][1])) { $countryID = CRM_Utils_Array::value('country_id', $this->_defaults['address'][1]); $stateID = CRM_Utils_Array::value('state_province_id', $this->_defaults['address'][1]); } CRM_Contact_BAO_Contact_Utils::buildOnBehalfForm($this, $this->_contactType, $countryID, $stateID, 'Contact Information', TRUE); $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); }
/** * View summary details of a contact. */ public function view() { // Add js for tabs, in-place editing, and jstree for tags CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Contact/Page/View/Summary.js', 2, 'html-header')->addStyleFile('civicrm', 'css/contactSummary.css', 2, 'html-header')->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header')->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')->addSetting(array('summaryPrint' => array('mode' => $this->_print), 'tabSettings' => array('active' => CRM_Utils_Request::retrieve('selectedChild', 'String', $this, FALSE, 'summary')))); $this->assign('summaryPrint', $this->_print); $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId); $session->pushUserContext($url); $params = array(); $defaults = array(); $ids = array(); $params['id'] = $params['contact_id'] = $this->_contactId; $params['noRelationships'] = $params['noNotes'] = $params['noGroups'] = TRUE; $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, TRUE); // Let summary page know if outbound mail is disabled so email links can be built conditionally $mailingBackend = Civi::settings()->get('mailing_backend'); $this->assign('mailingOutboundOption', $mailingBackend['outBound_option']); $communicationType = array('phone' => array('type' => 'phoneType', 'id' => 'phone_type', 'daoName' => 'CRM_Core_DAO_Phone', 'fieldName' => 'phone_type_id'), 'im' => array('type' => 'IMProvider', 'id' => 'provider', 'daoName' => 'CRM_Core_DAO_IM', 'fieldName' => 'provider_id'), 'website' => array('type' => 'websiteType', 'id' => 'website_type', 'daoName' => 'CRM_Core_DAO_Website', 'fieldName' => 'website_type_id'), 'address' => array('skip' => TRUE, 'customData' => 1), 'email' => array('skip' => TRUE), 'openid' => array('skip' => TRUE)); foreach ($communicationType as $key => $value) { if (!empty($defaults[$key])) { foreach ($defaults[$key] as &$val) { CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name')), FALSE); if (empty($value['skip'])) { $daoName = $value['daoName']; $pseudoConst = $daoName::buildOptions($value['fieldName'], 'get'); CRM_Utils_Array::lookupValue($val, $value['id'], $pseudoConst, FALSE); } } if (isset($value['customData'])) { foreach ($defaults[$key] as $blockId => $blockVal) { $idValue = $blockVal['id']; if ($key == 'address') { if (!empty($blockVal['master_id'])) { $idValue = $blockVal['master_id']; } } $groupTree = CRM_Core_BAO_CustomGroup::getTree(ucfirst($key), $this, $idValue); // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var. $defaults[$key][$blockId]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, "dnc_"); } // reset template variable since that won't be of any use, and could be misleading $this->assign("dnc_viewCustomData", NULL); } } } if (!empty($defaults['gender_id'])) { $defaults['gender_display'] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'gender_id', $defaults['gender_id']); } $communicationStyle = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id'); if (!empty($communicationStyle)) { if (!empty($defaults['communication_style_id'])) { $defaults['communication_style_display'] = $communicationStyle[CRM_Utils_Array::value('communication_style_id', $defaults)]; } else { // Make sure the field is displayed as long as it is active, even if it is unset for this contact. $defaults['communication_style_display'] = ''; } } // to make contact type label available in the template - $contactType = array_key_exists('contact_sub_type', $defaults) ? $defaults['contact_sub_type'] : $defaults['contact_type']; $defaults['contact_type_label'] = CRM_Contact_BAO_ContactType::contactTypePairs(TRUE, $contactType, ', '); // get contact tags $contactTags = CRM_Core_BAO_EntityTag::getContactTags($this->_contactId); if (!empty($contactTags)) { $defaults['contactTag'] = implode(', ', $contactTags); } $defaults['privacy_values'] = CRM_Core_SelectValues::privacy(); //Show blocks only if they are visible in edit form $this->_editOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_edit_options'); foreach ($this->_editOptions as $blockName => $value) { $varName = '_show' . $blockName; $this->{$varName} = $value; $this->assign(substr($varName, 1), $this->{$varName}); } // get contact name of shared contact names $sharedAddresses = array(); $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($defaults['address']); foreach ($defaults['address'] as $key => $addressValue) { if (!empty($addressValue['master_id']) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) { $sharedAddresses[$key]['shared_address_display'] = array('address' => $addressValue['display'], 'name' => $shareAddressContactNames[$addressValue['master_id']]['name']); } } $this->assign('sharedAddresses', $sharedAddresses); //get the current employer name if (CRM_Utils_Array::value('contact_type', $defaults) == 'Individual') { if ($contact->employer_id && $contact->organization_name) { $defaults['current_employer'] = $contact->organization_name; $defaults['current_employer_id'] = $contact->employer_id; } //for birthdate format with respect to birth format set $this->assign('birthDateViewFormat', CRM_Utils_Array::value('qfMapping', CRM_Utils_Date::checkBirthDateFormat())); } $defaults['external_identifier'] = $contact->external_identifier; $this->assign($defaults); // FIXME: when we sort out TZ isssues with DATETIME/TIMESTAMP, we can skip next query // also assign the last modifed details $lastModified = CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact'); $this->assign_by_ref('lastModified', $lastModified); $allTabs = array(); $weight = 10; $this->_viewOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_view_options', TRUE); // show the tabs only if user has generic access to CiviCRM $accessCiviCRM = CRM_Core_Permission::check('access CiviCRM'); $changeLog = $this->_viewOptions['log']; $this->assign_by_ref('changeLog', $changeLog); $components = CRM_Core_Component::getEnabledComponents(); foreach ($components as $name => $component) { if (!empty($this->_viewOptions[$name]) && CRM_Core_Permission::access($component->name)) { $elem = $component->registerTab(); // FIXME: not very elegant, probably needs better approach // allow explicit id, if not defined, use keyword instead if (array_key_exists('id', $elem)) { $i = $elem['id']; } else { $i = $component->getKeyword(); } $u = $elem['url']; //appending isTest to url for test soft credit CRM-3891. //FIXME: hack ajax url. $q = "reset=1&force=1&cid={$this->_contactId}"; if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) { $q .= "&isTest=1"; } $allTabs[] = array('id' => $i, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$u}", $q), 'title' => $elem['title'], 'weight' => $elem['weight'], 'count' => CRM_Contact_BAO_Contact::getCountComponent($u, $this->_contactId), 'class' => 'livePage'); // make sure to get maximum weight, rest of tabs go after // FIXME: not very elegant again if ($weight < $elem['weight']) { $weight = $elem['weight']; } } } $rest = array('activity' => array('title' => ts('Activities'), 'class' => 'livePage'), 'rel' => array('title' => ts('Relationships'), 'class' => 'livePage'), 'group' => array('title' => ts('Groups'), 'class' => 'ajaxForm'), 'note' => array('title' => ts('Notes'), 'class' => 'livePage'), 'tag' => array('title' => ts('Tags')), 'log' => array('title' => ts('Change Log'))); foreach ($rest as $k => $v) { if ($accessCiviCRM && !empty($this->_viewOptions[$k])) { $allTabs[] = $v + array('id' => $k, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$k}", "reset=1&cid={$this->_contactId}"), 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($k, $this->_contactId)); $weight += 10; } } // now add all the custom tabs $entityType = $this->get('contactType'); $activeGroups = CRM_Core_BAO_CustomGroup::getActiveGroups($entityType, 'civicrm/contact/view/cd', $this->_contactId); foreach ($activeGroups as $group) { $id = "custom_{$group['id']}"; $allTabs[] = array('id' => $id, 'url' => CRM_Utils_System::url($group['path'], $group['query'] . "&selectedChild={$id}"), 'title' => $group['title'], 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $group['table_name']), 'hideCount' => !$group['is_multiple'], 'class' => 'livePage'); $weight += 10; } $context = array('contact_id' => $this->_contactId); // see if any other modules want to add any tabs CRM_Utils_Hook::tabs($allTabs, $this->_contactId); CRM_Utils_Hook::tabset('civicrm/contact/view', $allTabs, $context); $allTabs[] = array('id' => 'summary', 'url' => '#contact-summary', 'title' => ts('Summary'), 'weight' => 0); // now sort the tabs based on weight usort($allTabs, array('CRM_Utils_Sort', 'cmpFunc')); $this->assign('allTabs', $allTabs); // hook for contact summary // ignored but needed to prevent warnings $contentPlacement = CRM_Utils_Hook::SUMMARY_BELOW; CRM_Utils_Hook::summary($this->_contactId, $content, $contentPlacement); if ($content) { $this->assign_by_ref('hookContent', $content); $this->assign('hookContentPlacement', $contentPlacement); } }
/** * Test case for retrieve( ). * * Test with all values. */ public function testRetrieve() { //take the common contact params $params = $this->contactParams(); $params['note'] = 'test note'; //create the contact with given params. $contact = CRM_Contact_BAO_Contact::create($params); //Now check $contact is object of contact DAO.. $this->assertInstanceOf('CRM_Contact_DAO_Contact', $contact, 'Check for created object'); $contactId = $contact->id; //create the organization contact with the given params. $orgParams = array('organization_name' => 'Test Organization ' . substr(sha1(rand()), 0, 4), 'contact_type' => 'Organization'); $orgContact = CRM_Contact_BAO_Contact::add($orgParams); $this->assertInstanceOf('CRM_Contact_DAO_Contact', $orgContact, 'Check for created object'); //create employee of relationship. CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contactId, $orgContact->id); //retrieve the contact values from database. $values = array(); $searchParams = array('contact_id' => $contactId); $retrieveContact = CRM_Contact_BAO_Contact::retrieve($searchParams, $values); //Now check $retrieveContact is object of contact DAO.. $this->assertInstanceOf('CRM_Contact_DAO_Contact', $retrieveContact, 'Check for retrieve object'); //Now check the ids. $this->assertEquals($contactId, $retrieveContact->id, 'Check for contact id'); //Now check values retrieve from database with params. $this->assertEquals($params['first_name'], $values['first_name'], 'Check for first name creation.'); $this->assertEquals($params['last_name'], $values['last_name'], 'Check for last name creation.'); $this->assertEquals($params['contact_type'], $values['contact_type'], 'Check for contact type creation.'); //Now check values of address $this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['address']), CRM_Utils_Array::value('1', $values['address'])); //Now check values of email $this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['email']), CRM_Utils_Array::value('1', $values['email'])); //Now check values of phone $this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['phone']), CRM_Utils_Array::value('1', $values['phone'])); //Now check values of mobile $this->assertAttributesEquals(CRM_Utils_Array::value('2', $params['phone']), CRM_Utils_Array::value('2', $values['phone'])); //Now check values of openid $this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['openid']), CRM_Utils_Array::value('1', $values['openid'])); //Now check values of im $this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['im']), CRM_Utils_Array::value('1', $values['im'])); //Now check values of Note Count. $this->assertEquals(1, $values['noteTotalCount'], 'Check for total note count'); foreach ($values['note'] as $key => $val) { $retrieveNote = CRM_Utils_Array::value('note', $val); //check the note value $this->assertEquals($params['note'], $retrieveNote, 'Check for note'); } //Now check values of Relationship Count. $this->assertEquals(1, $values['relationship']['totalCount'], 'Check for total relationship count'); foreach ($values['relationship']['data'] as $key => $val) { //Now check values of Relationship organization. $this->assertEquals($orgContact->id, $val['contact_id_b'], 'Check for organization'); //Now check values of Relationship type. $this->assertEquals('Employee of', $val['relation'], 'Check for relationship type'); //delete the organization. $this->contactDelete(CRM_Utils_Array::value('contact_id_b', $val)); } //delete all notes related to contact CRM_Core_BAO_Note::cleanContactNotes($contactId); //cleanup DB by deleting the contact $this->contactDelete($contactId); $this->quickCleanup(array('civicrm_contact')); }
/** * Format params for update and fill mode. * * @param array $params * reference to an array containing all the. * values for import * @param int $onDuplicate * @param int $cid * contact id. */ public function formatParams(&$params, $onDuplicate, $cid) { if ($onDuplicate == CRM_Import_Parser::DUPLICATE_SKIP) { return; } $contactParams = array('contact_id' => $cid); $defaults = array(); $contactObj = CRM_Contact_BAO_Contact::retrieve($contactParams, $defaults); $modeUpdate = $modeFill = FALSE; if ($onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) { $modeUpdate = TRUE; } if ($onDuplicate == CRM_Import_Parser::DUPLICATE_FILL) { $modeFill = TRUE; } $groupTree = CRM_Core_BAO_CustomGroup::getTree($params['contact_type'], CRM_Core_DAO::$_nullObject, $cid, 0, NULL); CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults, FALSE, FALSE); $locationFields = array('email' => 'email', 'phone' => 'phone', 'im' => 'name', 'website' => 'website', 'address' => 'address'); $contact = get_object_vars($contactObj); foreach ($params as $key => $value) { if ($key == 'id' || $key == 'contact_type') { continue; } if (array_key_exists($key, $locationFields)) { continue; } elseif (in_array($key, array('email_greeting', 'postal_greeting', 'addressee'))) { // CRM-4575, need to null custom if ($params["{$key}_id"] != 4) { $params["{$key}_custom"] = 'null'; } unset($params[$key]); } elseif ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key)) { $custom = TRUE; } else { $getValue = CRM_Utils_Array::retrieveValueRecursive($contact, $key); if ($key == 'contact_source') { $params['source'] = $params[$key]; unset($params[$key]); } if ($modeFill && isset($getValue)) { unset($params[$key]); } } } foreach ($locationFields as $locKeys) { if (is_array(CRM_Utils_Array::value($locKeys, $params))) { foreach ($params[$locKeys] as $key => $value) { if ($modeFill) { $getValue = CRM_Utils_Array::retrieveValueRecursive($contact, $locKeys); if (isset($getValue)) { foreach ($getValue as $cnt => $values) { if ($locKeys == 'website') { if ($getValue[$cnt]['website_type_id'] == $params[$locKeys][$key]['website_type_id']) { unset($params[$locKeys][$key]); } } else { if (!empty($getValue[$cnt]['location_type_id']) && !empty($params[$locKeys][$key]['location_type_id']) && $getValue[$cnt]['location_type_id'] == $params[$locKeys][$key]['location_type_id']) { unset($params[$locKeys][$key]); } } } } } } if (count($params[$locKeys]) == 0) { unset($params[$locKeys]); } } } }
public function testContributeOfflineforSoftcreditwithApi() { // Log in using webtestLogin() method $this->webtestLogin(); //create a contact and return the contact id $firstNameSoft = "John_" . substr(sha1(rand()), 0, 5); $lastNameSoft = "Doe_" . substr(sha1(rand()), 0, 5); $this->webtestAddContact($firstNameSoft, $lastNameSoft); $url = $this->parseURL(); $cid = $url['queryString']['cid']; $this->assertType('numeric', $cid); $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); $usedFor = 'Contribution'; $setHelp = 'Select your conference options.'; $financialType = $this->_testAddFinancialType(); $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType); // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form // which is where we are after adding Price Set. $sid = $this->urlArg('sid'); $this->assertType('numeric', $sid); $validStrings = array(); $fields = array('Full Conference' => 'Text', 'Meal Choice' => 'Select', 'Pre-conference Meetup?' => 'Radio', 'Evening Sessions' => 'CheckBox'); $this->_testAddPriceFields($fields, $validateStrings, $financialType); // load the Price Set Preview and check for expected values $this->_testVerifyPriceSet($validateStrings, $sid); $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", '_qf_Contribution_upload'); // create new contact using dialog $contact = $this->createDialogContact(); // select contribution type $this->select('financial_type_id', "label={$financialType}"); // fill in Received Date $this->webtestFillDate('receive_date'); // source $this->type('source', 'Mailer 1'); // select price set items $this->select('price_set_id', "label={$setTitle}"); $this->type("xpath=//input[@class='four crm-form-text required']", "1"); $this->click("xpath=//input[@class='crm-form-radio']"); $this->click("xpath=//input[@class='crm-form-checkbox']"); // select payment instrument type = Check and enter chk number $this->select('payment_instrument_id', 'value=4'); $this->waitForElementPresent('check_number'); $this->type('check_number', '1041'); $this->type('trxn_id', 'P20901X1' . rand(100, 10000)); $this->webtestFillAutocomplete("{$lastNameSoft}, {$firstNameSoft}", 'soft_credit_contact_id_1'); $this->type('soft_credit_amount_1', "65"); //Additional Detail section $this->click('AdditionalDetail'); $this->waitForElementPresent('thankyou_date'); $this->type('note', 'This is a test note.'); $this->type('invoice_id', time()); $this->webtestFillDate('thankyou_date'); // Clicking save. $this->clickLink('_qf_Contribution_upload', "xpath=//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span//a[text()='View']", FALSE); $this->assertTrue($this->isTextPresent('The contribution record has been saved.'), "Status message didn't show up after saving!"); //click through to the Contribution view screen $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']"); $this->waitForElementPresent('_qf_ContributionView_cancel-bottom'); // View Contribution Record and test for expected values $expected = array('From' => $contact['display_name'], 'Financial Type' => $financialType, 'Contribution Amount' => 'Contribution Total: $ 590.00', 'Payment Method' => 'Check', 'Check Number' => '1041', 'Contribution Status' => 'Completed'); $this->webtestVerifyTabularData($expected); $exp = array(2 => '$ 525.00', 3 => '$ 50.00', 4 => '$ 15.00'); foreach ($exp as $lab => $val) { $this->assertElementContainsText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[{$lab}]/td[3]", $val); } // verify if soft credit was created successfully $softCreditValues = array('Soft Credit To' => "{$firstNameSoft} {$lastNameSoft}", 'Amount' => '65.00'); foreach ($softCreditValues as $value) { $this->assertElementContainsText("css=table.crm-soft-credit-listing", $value); } // Check for Soft contact created $this->click("css=input#sort_name_navigation"); $this->type("css=input#sort_name_navigation", "{$lastNameSoft}, {$firstNameSoft}"); $this->typeKeys("css=input#sort_name_navigation", "{$lastNameSoft}, {$firstNameSoft}"); // wait for result list $this->waitForElementPresent("css=ul.ui-autocomplete li"); // visit contact summary page $this->click("css=ul.ui-autocomplete li"); $this->waitForPageToLoad($this->getTimeoutMsec()); $this->click('css=li#tab_contribute a'); $this->waitForElementPresent('link=Record Contribution (Check, Cash, EFT ...)'); $id = explode('id=', $this->getAttribute("xpath=//table[@class='selector row-highlight']/tbody//tr[@id='rowid']/td[8]/a[text()='View']@href")); $id = substr($id[1], 0, strpos($id[1], '&')); $this->click("xpath=//table[@class='selector row-highlight']/tbody//tr[@id='rowid']/td[8]/a"); $this->waitForElementPresent('_qf_ContributionView_cancel-bottom'); $this->webtestVerifyTabularData($expected); $params = array('contribution_id' => $id, 'version' => 3); // Retrieve contribution from the DB via api and verify DB values against view contribution page $fields = $this->webtest_civicrm_api('contribution', 'get', $params); $params['id'] = $params['contact_id'] = $fields['values'][$fields['id']]['soft_credit_to']; $softCreditContact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, TRUE); // View Contribution Record and test for expected values $expected = array('From' => $fields['values'][$fields['id']]['display_name'], 'Financial Type' => $fields['values'][$fields['id']]['financial_type'], 'Contribution Amount' => $fields['values'][$fields['id']]['total_amount'], 'Contribution Status' => $fields['values'][$fields['id']]['contribution_status'], 'Payment Method' => $fields['values'][$fields['id']]['payment_instrument'], 'Check Number' => $fields['values'][$fields['id']]['contribution_check_number']); $this->webtestVerifyTabularData($expected); // verify if soft credit $softCreditValues = array('Soft Credit To' => $softCreditContact->display_name, 'Amount' => '65.00'); foreach ($softCreditValues as $value) { $this->assertElementContainsText("css=table.crm-soft-credit-listing", $value); } }
/** * Apply variables for message to smarty template - this function is part of analysing what is in the huge * function & breaking it down into manageable chunks. Eventually it will be refactored into something else * Note we send directly from this function in some cases because it is only partly refactored * Don't call this function directly as the signature will change */ function _assignMessageVariablesToTemplate(&$values, $input, &$template, $recur = FALSE, $returnMessageText = True) { $template->assign('first_name', $this->_relatedObjects['contact']->first_name); $template->assign('last_name', $this->_relatedObjects['contact']->last_name); $template->assign('displayName', $this->_relatedObjects['contact']->display_name); if (!empty($values['lineItem']) && !empty($this->_relatedObjects['membership'])) { $template->assign('useForMember', true); } //assign honor infomation to receiptmessage $honorID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->id, 'honor_contact_id'); if (!empty($honorID)) { $honorDefault = $honorIds = array(); $honorIds['contribution'] = $this->id; $idParams = array('id' => $honorID, 'contact_id' => $honorID); CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault, $honorIds); $honorType = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'honor_type_id'); $template->assign('honor_block_is_active', 1); if (CRM_Utils_Array::value('prefix_id', $honorDefault)) { $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'); $template->assign('honor_prefix', $prefix[$honorDefault['prefix_id']]); } $template->assign('honor_first_name', CRM_Utils_Array::value('first_name', $honorDefault)); $template->assign('honor_last_name', CRM_Utils_Array::value('last_name', $honorDefault)); $template->assign('honor_email', CRM_Utils_Array::value('email', $honorDefault['email'][1])); $template->assign('honor_type', $honorType[$this->honor_type_id]); } $dao = new CRM_Contribute_DAO_ContributionProduct(); $dao->contribution_id = $this->id; if ($dao->find(TRUE)) { $premiumId = $dao->product_id; $template->assign('option', $dao->product_option); $productDAO = new CRM_Contribute_DAO_Product(); $productDAO->id = $premiumId; $productDAO->find(TRUE); $template->assign('selectPremium', TRUE); $template->assign('product_name', $productDAO->name); $template->assign('price', $productDAO->price); $template->assign('sku', $productDAO->sku); } $template->assign('title', CRM_Utils_Array::value('title', $values)); $amount = CRM_Utils_Array::value('total_amount', $input, CRM_Utils_Array::value('amount', $input), null); if (empty($amount) && isset($this->total_amount)) { $amount = $this->total_amount; } $template->assign('amount', $amount); // add the new contribution values if (strtolower($this->_component) == 'contribute') { //PCP Info $softDAO = new CRM_Contribute_DAO_ContributionSoft(); $softDAO->contribution_id = $this->id; if ($softDAO->find(TRUE)) { $template->assign('pcpBlock', TRUE); $template->assign('pcp_display_in_roll', $softDAO->pcp_display_in_roll); $template->assign('pcp_roll_nickname', $softDAO->pcp_roll_nickname); $template->assign('pcp_personal_note', $softDAO->pcp_personal_note); //assign the pcp page title for email subject $pcpDAO = new CRM_PCP_DAO_PCP(); $pcpDAO->id = $softDAO->pcp_id; if ($pcpDAO->find(TRUE)) { $template->assign('title', $pcpDAO->title); } } } if ($this->financial_type_id) { $values['financial_type_id'] = $this->financial_type_id; } $template->assign('trxn_id', $this->trxn_id); $template->assign('receive_date', CRM_Utils_Date::mysqlToIso($this->receive_date)); $template->assign('contributeMode', 'notify'); $template->assign('action', $this->is_test ? 1024 : 1); $template->assign('receipt_text', CRM_Utils_Array::value('receipt_text', $values)); $template->assign('is_monetary', 1); $template->assign('is_recur', (bool) $recur); $template->assign('currency', $this->currency); $template->assign('address', CRM_Utils_Address::format($input)); if ($this->_component == 'event') { $template->assign('title', $values['event']['title']); $participantRoles = CRM_Event_PseudoConstant::participantRole(); $viewRoles = array(); foreach (explode(CRM_Core_DAO::VALUE_SEPARATOR, $this->_relatedObjects['participant']->role_id) as $k => $v) { $viewRoles[] = $participantRoles[$v]; } $values['event']['participant_role'] = implode(', ', $viewRoles); $template->assign('event', $values['event']); $template->assign('location', $values['location']); $template->assign('customPre', $values['custom_pre_id']); $template->assign('customPost', $values['custom_post_id']); $isTest = FALSE; if ($this->_relatedObjects['participant']->is_test) { $isTest = TRUE; } $values['params'] = array(); //to get email of primary participant. $primaryEmail = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $this->_relatedObjects['participant']->contact_id, 'email', 'contact_id'); $primaryAmount[] = array('label' => $this->_relatedObjects['participant']->fee_level . ' - ' . $primaryEmail, 'amount' => $this->_relatedObjects['participant']->fee_amount); //build an array of cId/pId of participants $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($this->_relatedObjects['participant']->id, NULL, $this->_relatedObjects['contact']->id, $isTest, TRUE); unset($additionalIDs[$this->_relatedObjects['participant']->id]); //send receipt to additional participant if exists if (count($additionalIDs)) { $template->assign('isPrimary', 0); $template->assign('customProfile', NULL); //set additionalParticipant true $values['params']['additionalParticipant'] = TRUE; foreach ($additionalIDs as $pId => $cId) { $amount = array(); //to change the status pending to completed $additional = new CRM_Event_DAO_Participant(); $additional->id = $pId; $additional->contact_id = $cId; $additional->find(TRUE); $additional->register_date = $this->_relatedObjects['participant']->register_date; $additional->status_id = 1; $additionalParticipantInfo = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $additional->contact_id, 'email', 'contact_id'); //if additional participant dont have email //use display name. if (!$additionalParticipantInfo) { $additionalParticipantInfo = CRM_Contact_BAO_Contact::displayName($additional->contact_id); } $amount[0] = array('label' => $additional->fee_level, 'amount' => $additional->fee_amount); $primaryAmount[] = array('label' => $additional->fee_level . ' - ' . $additionalParticipantInfo, 'amount' => $additional->fee_amount); $additional->save(); $additional->free(); $template->assign('amount', $amount); CRM_Event_BAO_Event::sendMail($cId, $values, $pId, $isTest, $returnMessageText); } } //build an array of custom profile and assigning it to template $customProfile = CRM_Event_BAO_Event::buildCustomProfile($this->_relatedObjects['participant']->id, $values, NULL, $isTest); if (count($customProfile)) { $template->assign('customProfile', $customProfile); } // for primary contact $values['params']['additionalParticipant'] = FALSE; $template->assign('isPrimary', 1); $template->assign('amount', $primaryAmount); $template->assign('register_date', CRM_Utils_Date::isoToMysql($this->_relatedObjects['participant']->register_date)); if ($this->payment_instrument_id) { $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument(); $template->assign('paidBy', $paymentInstrument[$this->payment_instrument_id]); } // carry paylater, since we did not created billing, // so need to pull email from primary location, CRM-4395 $values['params']['is_pay_later'] = $this->_relatedObjects['participant']->is_pay_later; } return $template; }
/** * Build all the data structures needed to build the form. */ public function preProcess() { $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add'); $this->_dedupeButtonName = $this->getButtonName('refresh', 'dedupe'); $this->_duplicateButtonName = $this->getButtonName('upload', 'duplicate'); CRM_Core_Resources::singleton()->addStyleFile('civicrm', 'css/contactSummary.css', 2, 'html-header'); $session = CRM_Core_Session::singleton(); if ($this->_action == CRM_Core_Action::ADD) { // check for add contacts permissions if (!CRM_Core_Permission::check('add contacts')) { CRM_Utils_System::permissionDenied(); CRM_Utils_System::civiExit(); } $this->_contactType = CRM_Utils_Request::retrieve('ct', 'String', $this, TRUE, NULL, 'REQUEST'); if (!in_array($this->_contactType, array('Individual', 'Household', 'Organization'))) { CRM_Core_Error::statusBounce(ts('Could not get a contact id and/or contact type')); } $this->_isContactSubType = FALSE; if ($this->_contactSubType = CRM_Utils_Request::retrieve('cst', 'String', $this)) { $this->_isContactSubType = TRUE; } if ($this->_contactSubType && !CRM_Contact_BAO_ContactType::isExtendsContactType($this->_contactSubType, $this->_contactType, TRUE)) { CRM_Core_Error::statusBounce(ts("Could not get a valid contact subtype for contact type '%1'", array(1 => $this->_contactType))); } $this->_gid = CRM_Utils_Request::retrieve('gid', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET'); $this->_tid = CRM_Utils_Request::retrieve('tid', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET'); $typeLabel = CRM_Contact_BAO_ContactType::contactTypePairs(TRUE, $this->_contactSubType ? $this->_contactSubType : $this->_contactType); $typeLabel = implode(' / ', $typeLabel); CRM_Utils_System::setTitle(ts('New %1', array(1 => $typeLabel))); $session->pushUserContext(CRM_Utils_System::url('civicrm/dashboard', 'reset=1')); $this->_contactId = NULL; } else { //update mode if (!$this->_contactId) { $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); } if ($this->_contactId) { $defaults = array(); $params = array('id' => $this->_contactId); $returnProperities = array('id', 'contact_type', 'contact_sub_type', 'modified_date', 'is_deceased'); CRM_Core_DAO::commonRetrieve('CRM_Contact_DAO_Contact', $params, $defaults, $returnProperities); if (empty($defaults['id'])) { CRM_Core_Error::statusBounce(ts('A Contact with that ID does not exist: %1', array(1 => $this->_contactId))); } $this->_contactType = CRM_Utils_Array::value('contact_type', $defaults); $this->_contactSubType = CRM_Utils_Array::value('contact_sub_type', $defaults); // check for permissions $session = CRM_Core_Session::singleton(); if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) { CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to edit this contact.')); } $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId); if ($defaults['is_deceased']) { $displayName .= ' <span class="crm-contact-deceased">(deceased)</span>'; } $displayName = ts('Edit %1', array(1 => $displayName)); // Check if this is default domain contact CRM-10482 if (CRM_Contact_BAO_Contact::checkDomainContact($this->_contactId)) { $displayName .= ' (' . ts('default organization') . ')'; } // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container CRM_Utils_System::setTitle($displayName); $context = CRM_Utils_Request::retrieve('context', 'String', $this); $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); $urlParams = 'reset=1&cid=' . $this->_contactId; if ($context) { $urlParams .= "&context={$context}"; } if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&key={$qfKey}"; } $session->pushUserContext(CRM_Utils_System::url('civicrm/contact/view', $urlParams)); $values = $this->get('values'); // get contact values. if (!empty($values)) { $this->_values = $values; } else { $params = array('id' => $this->_contactId, 'contact_id' => $this->_contactId, 'noRelationships' => TRUE, 'noNotes' => TRUE, 'noGroups' => TRUE); $contact = CRM_Contact_BAO_Contact::retrieve($params, $this->_values, TRUE); $this->set('values', $this->_values); } } else { CRM_Core_Error::statusBounce(ts('Could not get a contact_id and/or contact_type')); } } // parse street address, CRM-5450 $this->_parseStreetAddress = $this->get('parseStreetAddress'); if (!isset($this->_parseStreetAddress)) { $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options'); $this->_parseStreetAddress = FALSE; if (!empty($addressOptions['street_address']) && !empty($addressOptions['street_address_parsing'])) { $this->_parseStreetAddress = TRUE; } $this->set('parseStreetAddress', $this->_parseStreetAddress); } $this->assign('parseStreetAddress', $this->_parseStreetAddress); $this->_editOptions = $this->get('contactEditOptions'); if (CRM_Utils_System::isNull($this->_editOptions)) { $this->_editOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_edit_options', TRUE, NULL, FALSE, 'name', TRUE, 'AND v.filter = 0'); $this->set('contactEditOptions', $this->_editOptions); } // build demographics only for Individual contact type if ($this->_contactType != 'Individual' && array_key_exists('Demographics', $this->_editOptions)) { unset($this->_editOptions['Demographics']); } // in update mode don't show notes if ($this->_contactId && array_key_exists('Notes', $this->_editOptions)) { unset($this->_editOptions['Notes']); } $this->assign('editOptions', $this->_editOptions); $this->assign('contactType', $this->_contactType); $this->assign('contactSubType', $this->_contactSubType); //build contact subtype form element, CRM-6864 $buildContactSubType = TRUE; if ($this->_contactSubType && $this->_action & CRM_Core_Action::ADD) { $buildContactSubType = FALSE; } $this->assign('buildContactSubType', $buildContactSubType); // get the location blocks. $this->_blocks = $this->get('blocks'); if (CRM_Utils_System::isNull($this->_blocks)) { $this->_blocks = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_edit_options', TRUE, NULL, FALSE, 'name', TRUE, 'AND v.filter = 1'); $this->set('blocks', $this->_blocks); } $this->assign('blocks', $this->_blocks); // this is needed for custom data. $this->assign('entityID', $this->_contactId); // also keep the convention. $this->assign('contactId', $this->_contactId); // location blocks. CRM_Contact_Form_Location::preProcess($this); // retain the multiple count custom fields value if (!empty($_POST['hidden_custom'])) { $customGroupCount = CRM_Utils_Array::value('hidden_custom_group_count', $_POST); if ($contactSubType = CRM_Utils_Array::value('contact_sub_type', $_POST)) { $paramSubType = implode(',', $contactSubType); } $this->_getCachedTree = FALSE; unset($customGroupCount[0]); foreach ($customGroupCount as $groupID => $groupCount) { if ($groupCount > 1) { $this->set('groupID', $groupID); //loop the group for ($i = 0; $i <= $groupCount; $i++) { CRM_Custom_Form_CustomData::preProcess($this, NULL, $contactSubType, $i, $this->_contactType); CRM_Contact_Form_Edit_CustomData::buildQuickForm($this); } } } //reset all the ajax stuff, for normal processing if (isset($this->_groupTree)) { $this->_groupTree = NULL; } $this->set('groupID', NULL); $this->_getCachedTree = TRUE; } // execute preProcess dynamically by js else execute normal preProcess if (array_key_exists('CustomData', $this->_editOptions)) { //assign a parameter to pass for sub type multivalue //custom field to load if ($this->_contactSubType || isset($paramSubType)) { $paramSubType = isset($paramSubType) ? $paramSubType : str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ',', trim($this->_contactSubType, CRM_Core_DAO::VALUE_SEPARATOR)); $this->assign('paramSubType', $paramSubType); } if (CRM_Utils_Request::retrieve('type', 'String', CRM_Core_DAO::$_nullObject)) { CRM_Contact_Form_Edit_CustomData::preProcess($this); } else { $contactSubType = $this->_contactSubType; // need contact sub type to build related grouptree array during post process if (!empty($_POST['contact_sub_type'])) { $contactSubType = $_POST['contact_sub_type']; } //only custom data has preprocess hence directly call it CRM_Custom_Form_CustomData::preProcess($this, NULL, $contactSubType, 1, $this->_contactType, $this->_contactId); $this->assign('customValueCount', $this->_customValueCount); } } }
/** * This function sets the default values for the form. Note that in edit/view mode * the default values are retrieved from the database * * @access public * @return None */ function setDefaultValues() { $defaults = array(); $params = array(); if ($this->_action & CRM_CORE_ACTION_ADD) { // set group and tag defaults if any if ($this->_gid) { $defaults['group'][$this->_gid] = 1; } if ($this->_tid) { $defaults['tag'][$this->_tid] = 1; } if (CRM_CONTACT_FORM_EDIT_LOCATION_BLOCKS >= 1) { // set the is_primary location for the first location $defaults['location'] = array(); $locationTypeKeys = array_filter(array_keys(CRM_Core_PseudoConstant::locationType()), 'is_int'); sort($locationTypeKeys); // also set the location types for each location block for ($i = 0; $i < CRM_CONTACT_FORM_EDIT_LOCATION_BLOCKS; $i++) { $defaults['location'][$i + 1] = array(); //$defaults['location'][$i+1]['location_type_id'] = $locationTypeKeys[$i]; if ($i == 0) { $defaultLocation =& new CRM_Core_BAO_LocationType(); $locationType = $defaultLocation->getDefault(); $defaults['location'][$i + 1]['location_type_id'] = $locationType->id; } else { $defaults['location'][$i + 1]['location_type_id'] = $locationTypeKeys[$i]; } $defaults['location'][$i + 1]['address'] = array(); $config =& CRM_Core_Config::singleton(); $countryIsoCodes =& CRM_Core_PseudoConstant::countryIsoCode(); $defaultCountryId = array_search($config->defaultContactCountry, $countryIsoCodes); $defaults['location'][$i + 1]['address']['country_id'] = $defaultCountryId; } $defaults['location'][1]['is_primary'] = true; } } else { // this is update mode // get values from contact table $params['id'] = $params['contact_id'] = $this->_contactId; $ids = array(); $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, $ids); $this->set('ids', $ids); $this->assign('contactId', $this->_contactId); // also set contact_type, since this is used in showHide routines // to decide whether to display certain blocks (demographics) $this->_contactType = CRM_Utils_Array::value('contact_type', $defaults); // set the group and tag ids CRM_Contact_Form_GroupTag::setDefaults($this->_contactId, $defaults, CRM_CONTACT_FORM_GROUPTAG_ALL); } // use most recently posted values if any to display show hide blocks $params = $this->controller->exportValues($this->_name); if (!empty($params)) { $this->setShowHide($params, true); } else { $this->setShowHide($defaults, false); } // do we need inactive options ? if ($this->_action & (CRM_CORE_ACTION_VIEW | CRM_CORE_ACTION_BROWSE)) { $inactiveNeeded = true; $viewMode = true; } else { $viewMode = false; $inactiveNeeded = false; } CRM_Core_BAO_CustomGroup::setDefaults($this->_groupTree, $defaults, $viewMode, $inactiveNeeded); return $defaults; }