示例#1
0
 /**
  * Process price set and line items.
  *
  * @param int $entityId
  * @param array $lineItem
  *   Line item array.
  * @param object $contributionDetails
  * @param string $entityTable
  *   Entity table.
  *
  * @param bool $update
  *
  * @return void
  */
 public static function processPriceSet($entityId, $lineItem, $contributionDetails = NULL, $entityTable = 'civicrm_contribution', $update = FALSE)
 {
     if (!$entityId || !is_array($lineItem) || CRM_Utils_system::isNull($lineItem)) {
         return;
     }
     foreach ($lineItem as $priceSetId => $values) {
         if (!$priceSetId) {
             continue;
         }
         foreach ($values as $line) {
             $line['entity_table'] = $entityTable;
             if (empty($line['entity_id'])) {
                 $line['entity_id'] = $entityId;
             }
             if (!empty($line['membership_type_id'])) {
                 $line['entity_table'] = 'civicrm_membership';
             }
             if (!empty($contributionDetails->id)) {
                 $line['contribution_id'] = $contributionDetails->id;
                 if ($line['entity_table'] == 'civicrm_contribution') {
                     $line['entity_id'] = $contributionDetails->id;
                 }
             }
             // if financial type is not set and if price field value is NOT NULL
             // get financial type id of price field value
             if (!empty($line['price_field_value_id']) && empty($line['financial_type_id'])) {
                 $line['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $line['price_field_value_id'], 'financial_type_id');
             }
             $lineItems = CRM_Price_BAO_LineItem::create($line);
             if (!$update && $contributionDetails) {
                 CRM_Financial_BAO_FinancialItem::add($lineItems, $contributionDetails);
                 if (isset($line['tax_amount'])) {
                     CRM_Financial_BAO_FinancialItem::add($lineItems, $contributionDetails, TRUE);
                 }
             }
         }
     }
 }
示例#2
0
 /**
  * Function returns formatted groupTree, sothat form can be easily build in template
  *
  * @param array  $groupTree associated array
  * @param int    $groupCount group count by default 1, but can varry for multiple value custom data 
  * @param object form object 
  *
  * @return array $formattedGroupTree
  */
 static function formatGroupTree(&$groupTree, $groupCount = 1, &$form)
 {
     $formattedGroupTree = array();
     $uploadNames = array();
     foreach ($groupTree as $key => $value) {
         if ($key === 'info') {
             continue;
         }
         // add group information
         $formattedGroupTree[$key]['name'] = CRM_Utils_Array::value('name', $value);
         $formattedGroupTree[$key]['title'] = CRM_Utils_Array::value('title', $value);
         $formattedGroupTree[$key]['help_pre'] = CRM_Utils_Array::value('help_pre', $value);
         $formattedGroupTree[$key]['help_post'] = CRM_Utils_Array::value('help_post', $value);
         $formattedGroupTree[$key]['collapse_display'] = CRM_Utils_Array::value('collapse_display', $value);
         $formattedGroupTree[$key]['collapse_adv_display'] = CRM_Utils_Array::value('collapse_adv_display', $value);
         // this params needed of bulding multiple values
         $formattedGroupTree[$key]['is_multiple'] = CRM_Utils_Array::value('is_multiple', $value);
         $formattedGroupTree[$key]['extends'] = CRM_Utils_Array::value('extends', $value);
         $formattedGroupTree[$key]['extends_entity_column_id'] = CRM_Utils_Array::value('extends_entity_column_id', $value);
         $formattedGroupTree[$key]['extends_entity_column_value'] = CRM_Utils_Array::value('extends_entity_column_value', $value);
         $formattedGroupTree[$key]['subtype'] = CRM_Utils_Array::value('subtype', $value);
         $formattedGroupTree[$key]['max_multiple'] = CRM_Utils_Array::value('max_multiple', $value);
         // add field information
         foreach ($value['fields'] as $k => $properties) {
             $properties['element_name'] = "custom_{$k}_-{$groupCount}";
             if (isset($properties['customValue']) && !CRM_Utils_system::isNull($properties['customValue'])) {
                 if (isset($properties['customValue'][$groupCount])) {
                     $properties['element_name'] = "custom_{$k}_{$properties['customValue'][$groupCount]['id']}";
                     if ($properties['data_type'] == 'File') {
                         $properties['element_value'] = $properties['customValue'][$groupCount];
                         $uploadNames[] = $properties['element_name'];
                     } else {
                         $properties['element_value'] = $properties['customValue'][$groupCount]['data'];
                     }
                 }
             }
             unset($properties['customValue']);
             $formattedGroupTree[$key]['fields'][$k] = $properties;
         }
     }
     if ($form) {
         // hack for field type File
         $formUploadNames = $form->get('uploadNames');
         if (is_array($formUploadNames)) {
             $uploadNames = array_unique(array_merge($formUploadNames, $uploadNames));
         }
         $form->set('uploadNames', $uploadNames);
     }
     return $formattedGroupTree;
 }
 /**
  * Function to process price set and line items.
  * @param int $contributionId contribution id
  * @param array $lineItem line item array
  * @param object $contributionDetails
  * @param decimal $initAmount amount
  * @param string $entityTable entity table
  *
  * @access public
  * @return void
  * @static
  */
 static function processPriceSet($entityId, $lineItem, $contributionDetails = NULL, $entityTable = 'civicrm_contribution', $update = FALSE)
 {
     if (!$entityId || !is_array($lineItem) || CRM_Utils_system::isNull($lineItem)) {
         return;
     }
     foreach ($lineItem as $priceSetId => $values) {
         if (!$priceSetId) {
             continue;
         }
         foreach ($values as $line) {
             $line['entity_table'] = $entityTable;
             $line['entity_id'] = $entityId;
             // if financial type is not set and if price field value is NOT NULL
             // get financial type id of price field value
             if (CRM_Utils_Array::value('price_field_value_id', $line) && !CRM_Utils_Array::value('financial_type_id', $line)) {
                 $line['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $line['price_field_value_id'], 'financial_type_id');
             }
             $lineItems = CRM_Price_BAO_LineItem::create($line);
             if (!$update && $contributionDetails) {
                 CRM_Financial_BAO_FinancialItem::add($lineItems, $contributionDetails);
             }
         }
     }
 }
 /** 
  * Function to process price set and line items. 
  * 
  * @access public 
  * @return None 
  */
 function processPriceSet($contributionId, $lineItem)
 {
     if (!$contributionId || !is_array($lineItem) || CRM_Utils_system::isNull($lineItem)) {
         return;
     }
     require_once 'CRM/Price/BAO/Set.php';
     require_once 'CRM/Price/BAO/LineItem.php';
     foreach ($lineItem as $priceSetId => $values) {
         if (!$priceSetId) {
             continue;
         }
         foreach ($values as $line) {
             $line['entity_table'] = 'civicrm_contribution';
             $line['entity_id'] = $contributionId;
             CRM_Price_BAO_LineItem::create($line);
         }
         CRM_Price_BAO_Set::addTo('civicrm_contribution', $contributionId, $priceSetId);
     }
 }
示例#5
0
文件: Merge.php 项目: ksecor/civicrm
 function preProcess()
 {
     require_once 'api/v2/Contact.php';
     require_once 'CRM/Core/BAO/CustomGroup.php';
     require_once 'CRM/Core/OptionGroup.php';
     require_once 'CRM/Core/OptionValue.php';
     if (!CRM_Core_Permission::check('administer CiviCRM')) {
         CRM_Core_Error::fatal(ts('You do not have access to this page'));
     }
     $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, true);
     $oid = CRM_Utils_Request::retrieve('oid', 'Positive', $this, true);
     $rgid = CRM_Utils_Request::retrieve('rgid', 'Positive', $this, false);
     $gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, false);
     $session =& CRM_Core_Session::singleton();
     // context fixed.
     if ($rgid) {
         $urlParam = "reset=1&action=browse&rgid={$rgid}";
         if ($gid) {
             $urlParam .= "&gid={$gid}";
         }
         $session->pushUserContext(CRM_Utils_system::url('civicrm/admin/dedupefind', $urlParam));
     }
     // ensure that oid is not the current user, if so refuse to do the merge
     if ($session->get('userID') == $oid) {
         $display_name = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $oid, 'display_name');
         $message = ts('The contact record which is linked to the currently logged in user account - \'%1\' - cannot be deleted.', array(1 => $display_name));
         CRM_Core_Error::statusBounce($message);
     }
     $diffs = CRM_Dedupe_Merger::findDifferences($cid, $oid);
     $mainParams = array('contact_id' => $cid, 'return.display_name' => 1);
     $otherParams = array('contact_id' => $oid, 'return.display_name' => 1);
     // API 2 has to have the requested fields spelt-out for it
     foreach (CRM_Dedupe_Merger::$validFields as $field) {
         $mainParams["return.{$field}"] = $otherParams["return.{$field}"] = 1;
     }
     $main =& civicrm_contact_get($mainParams);
     //CRM-4524
     $main = reset($main);
     if ($main['contact_id'] != $cid) {
         CRM_Core_Error::fatal(ts('The main contact record does not exist'));
     }
     $other =& civicrm_contact_get($otherParams);
     //CRM-4524
     $other = reset($other);
     if ($other['contact_id'] != $oid) {
         CRM_Core_Error::fatal(ts('The other contact record does not exist'));
     }
     $this->assign('contact_type', $main['contact_type']);
     $this->assign('main_name', $main['display_name']);
     $this->assign('other_name', $other['display_name']);
     $this->assign('main_cid', $main['contact_id']);
     $this->assign('other_cid', $other['contact_id']);
     $this->_cid = $cid;
     $this->_oid = $oid;
     $this->_rgid = $rgid;
     $this->_contactType = $main['contact_type'];
     $this->addElement('checkbox', 'toggleSelect', null, null, array('onclick' => "return toggleCheckboxVals('move_',this);"));
     require_once "CRM/Contact/DAO/Contact.php";
     $fields =& CRM_Contact_DAO_Contact::fields();
     // FIXME: there must be a better way
     foreach (array('main', 'other') as $moniker) {
         $contact =& ${$moniker};
         $specialValues[$moniker] = array('preferred_communication_method' => $contact['preferred_communication_method']);
         $names = array('preferred_communication_method' => array('newName' => 'preferred_communication_method_display', 'groupName' => 'preferred_communication_method'));
         CRM_Core_OptionGroup::lookupValues($specialValues[$moniker], $names);
     }
     foreach (CRM_Core_OptionValue::getFields() as $field => $params) {
         $fields[$field]['title'] = $params['title'];
     }
     if (!isset($diffs['contact'])) {
         $diffs['contact'] = array();
     }
     foreach ($diffs['contact'] as $field) {
         foreach (array('main', 'other') as $moniker) {
             $contact =& ${$moniker};
             $value = CRM_Utils_Array::value($field, $contact);
             $label = isset($specialValues[$moniker][$field]) ? $specialValues[$moniker]["{$field}_display"] : $value;
             if ($fields[$field]['type'] == CRM_Utils_Type::T_DATE) {
                 if ($value) {
                     $value = str_replace('-', '', $value);
                     $label = CRM_Utils_Date::customFormat($label);
                 } else {
                     $value = "null";
                 }
             } elseif ($fields[$field]['type'] == CRM_Utils_Type::T_BOOLEAN) {
                 if ($label === '0') {
                     $label = ts('[ ]');
                 }
                 if ($label === '1') {
                     $label = ts('[x]');
                 }
             }
             $rows["move_{$field}"][$moniker] = $label;
             if ($moniker == 'other') {
                 if ($value === null) {
                     $value = 'null';
                 }
                 if ($value === 0 or $value === '0') {
                     $value = $this->_qfZeroBug;
                 }
                 $this->addElement('advcheckbox', "move_{$field}", null, null, null, $value);
             }
         }
         $rows["move_{$field}"]['title'] = $fields[$field]['title'];
     }
     // handle location blocks.
     require_once 'api/v2/Location.php';
     $mainParams['version'] = $otherParams['version'] = '3.0';
     $locations['main'] =& civicrm_location_get($mainParams);
     $locations['other'] =& civicrm_location_get($otherParams);
     $allLocationTypes = CRM_Core_PseudoConstant::locationType();
     $mainLocAddress = array();
     foreach (array('Email', 'Phone', 'IM', 'OpenID', 'Address') as $block) {
         $name = strtolower($block);
         foreach (array('main', 'other') as $moniker) {
             $blockValue = CRM_Utils_Array::value($name, $locations[$moniker], array());
             if (empty($blockValue)) {
                 $locValue[$moniker][$name] = 0;
                 $locLabel[$moniker][$name] = array();
                 $locTypes[$moniker][$name] = array();
             } else {
                 $locValue[$moniker][$name] = true;
                 foreach ($blockValue as $count => $blkValues) {
                     $fldName = $name;
                     $locTypeId = $blkValues['location_type_id'];
                     if ($name == 'im') {
                         $fldName = 'name';
                     }
                     if ($name == 'address') {
                         $fldName = 'display';
                     }
                     $locLabel[$moniker][$name][$count] = $blkValues[$fldName];
                     $locTypes[$moniker][$name][$count] = $locTypeId;
                     if ($moniker == 'main' && $name == 'address') {
                         $mainLocAddress["main_{$locTypeId}"] = $blkValues[$fldName];
                         $this->_locBlockIds['main']['address'][$locTypeId] = $blkValues['id'];
                     } else {
                         $this->_locBlockIds[$moniker][$name][$count] = $blkValues['id'];
                     }
                 }
             }
         }
         if ($locValue['other'][$name] != 0) {
             foreach ($locLabel['other'][$name] as $count => $value) {
                 $locTypeId = $locTypes['other'][$name][$count];
                 $rows["move_location_{$name}_{$count}"]['other'] = $value;
                 $rows["move_location_{$name}_{$count}"]['main'] = $locLabel['main'][$name][$count];
                 $rows["move_location_{$name}_{$count}"]['title'] = ts('%1:%2:%3', array(1 => $block, 2 => $count, 3 => $allLocationTypes[$locTypeId]));
                 $this->addElement('advcheckbox', "move_location_{$name}_{$count}");
                 // make sure default location type is always on top
                 $mainLocTypeId = CRM_Utils_Array::value($count, $locTypes['main'][$name], $locTypeId);
                 $locTypeValues = $allLocationTypes;
                 $defaultLocType = array($mainLocTypeId => $locTypeValues[$mainLocTypeId]);
                 unset($locTypeValues[$mainLocTypeId]);
                 // keep 1-1 mapping for address - location type.
                 $js = null;
                 if ($name == 'address' && !empty($mainLocAddress)) {
                     $js = array('onChange' => "mergeAddress( this, {$count} );");
                 }
                 $this->addElement('select', "location[{$name}][{$count}][locTypeId]", null, $defaultLocType + $locTypeValues, $js);
                 if ($name != 'address') {
                     $this->addElement('advcheckbox', "location[{$name}][{$count}][operation]", null, ts('add new'));
                 }
             }
         }
     }
     $this->assign('mainLocAddress', json_encode($mainLocAddress));
     // handle custom fields
     $mainTree =& CRM_Core_BAO_CustomGroup::getTree($this->_contactType, $this, $this->_cid, -1);
     $otherTree =& CRM_Core_BAO_CustomGroup::getTree($this->_contactType, $this, $this->_oid, -1);
     if (!isset($diffs['custom'])) {
         $diffs['custom'] = array();
     }
     foreach ($otherTree as $gid => $group) {
         $foundField = false;
         if (!isset($group['fields'])) {
             continue;
         }
         foreach ($group['fields'] as $fid => $field) {
             if (in_array($fid, $diffs['custom'])) {
                 if (!$foundField) {
                     $rows["custom_group_{$gid}"]['title'] = $group['title'];
                     $foundField = true;
                 }
                 if (is_array($mainTree[$gid]['fields'][$fid]['customValue'])) {
                     foreach ($mainTree[$gid]['fields'][$fid]['customValue'] as $valueId => $values) {
                         $rows["move_custom_{$fid}"]['main'] = CRM_Core_BAO_CustomGroup::formatCustomValues($values, $field);
                     }
                 }
                 if (is_array($otherTree[$gid]['fields'][$fid]['customValue'])) {
                     foreach ($otherTree[$gid]['fields'][$fid]['customValue'] as $valueId => $values) {
                         $rows["move_custom_{$fid}"]['other'] = CRM_Core_BAO_CustomGroup::formatCustomValues($values, $field);
                         $value = $values['data'] ? $values['data'] : $this->_qfZeroBug;
                     }
                 }
                 $rows["move_custom_{$fid}"]['title'] = $field['label'];
                 $this->addElement('advcheckbox', "move_custom_{$fid}", null, null, null, $value);
             }
         }
     }
     $this->assign('rows', $rows);
     // add the related tables and unset the ones that don't sport any of the duplicate contact's info
     $relTables = CRM_Dedupe_Merger::relTables();
     $activeRelTables = CRM_Dedupe_Merger::getActiveRelTables($oid);
     foreach ($relTables as $name => $null) {
         if (!in_array($name, $activeRelTables)) {
             unset($relTables[$name]);
             continue;
         }
         $this->addElement('checkbox', "move_{$name}");
         $relTables[$name]['main_url'] = str_replace('$cid', $cid, $relTables[$name]['url']);
         $relTables[$name]['other_url'] = str_replace('$cid', $oid, $relTables[$name]['url']);
     }
     foreach ($relTables as $name => $null) {
         $relTables["move_{$name}"] = $relTables[$name];
         unset($relTables[$name]);
     }
     $this->assign('rel_tables', $relTables);
 }
 /**
  * function to set default values for address block
  *
  * @param array  $defaults  defaults associated array
  * @param object $form     form object
  *
  * @static
  * @access public
  */
 static function setDefaultValues(&$defaults, &$form)
 {
     $addressValues = array();
     if (isset($defaults['address']) && is_array($defaults['address']) && !CRM_Utils_system::isNull($defaults['address'])) {
         // start of contact shared adddress defaults
         $sharedAddresses = array();
         $masterAddress = array();
         // get contact name of shared contact names
         $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']);
             } else {
                 $defaults['address'][$key]['use_shared_address'] = 0;
             }
             //check if any address is shared by any other contacts
             $masterAddress[$key] = CRM_Core_BAO_Address::checkContactSharedAddress($addressValue['id']);
         }
         $form->assign('sharedAddresses', $sharedAddresses);
         $form->assign('masterAddress', $masterAddress);
         // end of shared address defaults
         // start of parse address functionality
         // build street address, CRM-5450.
         if ($form->_parseStreetAddress) {
             $parseFields = array('street_address', 'street_number', 'street_name', 'street_unit');
             foreach ($defaults['address'] as $cnt => &$address) {
                 $streetAddress = NULL;
                 foreach (array('street_number', 'street_number_suffix', 'street_name', 'street_unit') as $fld) {
                     if (in_array($fld, array('street_name', 'street_unit'))) {
                         $streetAddress .= ' ';
                     }
                     $streetAddress .= CRM_Utils_Array::value($fld, $address);
                 }
                 $streetAddress = trim($streetAddress);
                 if (!empty($streetAddress)) {
                     $address['street_address'] = $streetAddress;
                 }
                 if (isset($address['street_number'])) {
                     $address['street_number'] .= CRM_Utils_Array::value('street_number_suffix', $address);
                 }
                 // build array for set default.
                 foreach ($parseFields as $field) {
                     $addressValues["{$field}_{$cnt}"] = CRM_Utils_Array::value($field, $address);
                 }
                 // don't load fields, use js to populate.
                 foreach (array('street_number', 'street_name', 'street_unit') as $f) {
                     if (isset($address[$f])) {
                         unset($address[$f]);
                     }
                 }
             }
             $form->assign('allAddressFieldValues', json_encode($addressValues));
             //hack to handle show/hide address fields.
             $parsedAddress = array();
             if ($form->_contactId && CRM_Utils_Array::value('address', $_POST) && is_array($_POST['address'])) {
                 foreach ($_POST['address'] as $cnt => $values) {
                     $showField = 'streetAddress';
                     foreach (array('street_number', 'street_name', 'street_unit') as $fld) {
                         if (CRM_Utils_Array::value($fld, $values)) {
                             $showField = 'addressElements';
                             break;
                         }
                     }
                     $parsedAddress[$cnt] = $showField;
                 }
             }
             $form->assign('showHideAddressFields', $parsedAddress);
             $form->assign('loadShowHideAddressFields', empty($parsedAddress) ? FALSE : TRUE);
         }
         // end of parse address functionality
     }
 }
 /**
  * Function to process price set and line items.
  *
  * @access public
  *
  * @return None
  */
 function processPriceSet($contributionId, $lineItem, $entityTable = 'civicrm_contribution')
 {
     if (!$contributionId || !is_array($lineItem) || CRM_Utils_system::isNull($lineItem)) {
         return;
     }
     foreach ($lineItem as $priceSetId => $values) {
         if (!$priceSetId) {
             continue;
         }
         foreach ($values as $line) {
             $line['entity_table'] = $entityTable;
             $line['entity_id'] = $contributionId;
             CRM_Price_BAO_LineItem::create($line);
         }
     }
 }
 /**
  * Compute any messages which should be displayed after upgrade
  *
  * @param $postUpgradeMessage string, alterable
  * @param $rev string, an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs
  * @return void
  */
 function setPostUpgradeMessage(&$postUpgradeMessage, $rev)
 {
     if ($rev == '4.2.alpha1') {
         $postUpgradeMessage .= '<br />' . ts('Default versions of the following System Workflow Message Templates have been modified to handle new functionality: <ul><li>Events - Registration Confirmation and Receipt (on-line)</li><li>Pledges - Acknowledgement</li><li>Pledges - Payment Reminder</li></ul>. If you have modified these templates, please review the new default versions and implement updates as needed to your copies (Administer > Communications > Message Templates > System Workflow Messages).');
     }
     if ($rev == '4.2.beta5') {
         $config = CRM_Core_Config::singleton();
         if (!empty($config->extensionsDir)) {
             $postUpgradeMessage .= '<br />' . ts('Please <a href="%1" target="_blank">configure the Extension Resource URL</a>.', array(1 => CRM_Utils_system::url('civicrm/admin/setting/url', 'reset=1')));
         }
     }
     if ($rev == '4.2.7') {
         $postUpgradeMessage .= '<br />' . ts('If you have configured a report instance to allow anonymous access, you will need to reset the permission to Everyone for that instance (under the Report Settings pane).');
     }
 }
 /**
  * Function to process price set and line items.
  *
  * @access public
  *
  * @return None
  */
 function processPriceSet($membershipId, $lineItem)
 {
     if (!$membershipId || !is_array($lineItem) || CRM_Utils_system::isNull($lineItem)) {
         return;
     }
     foreach ($lineItem as $priceSetId => $values) {
         if (!$priceSetId) {
             continue;
         }
         foreach ($values as $line) {
             $line['entity_table'] = 'civicrm_membership';
             $line['entity_id'] = $membershipId;
             CRM_Price_BAO_LineItem::create($line);
         }
     }
 }
 public function postProcess()
 {
     $formValues = $this->exportValues();
     // reset all selected contact ids from session
     // when we came from search context, CRM-3526
     $session = CRM_Core_Session::singleton();
     if ($session->get('selectedSearchContactIds')) {
         $session->resetScope('selectedSearchContactIds');
     }
     $formValues['main_details'] = $formValues['other_details'] = array();
     $formValues['main_details']['contact_type'] = $this->_contactType;
     $formValues['main_details']['loc_block_ids'] = $this->_locBlockIds['main'];
     $formValues['other_details']['loc_block_ids'] = $this->_locBlockIds['other'];
     CRM_Dedupe_Merger::moveAllBelongings($this->_cid, $this->_oid, $formValues);
     CRM_Core_Session::setStatus(ts('The contacts have been merged.'));
     $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_cid}");
     if (CRM_Utils_Array::value('_qf_Merge_submit', $formValues)) {
         $listParamsURL = "reset=1&action=update&rgid={$this->_rgid}";
         if ($this->_gid) {
             $listParamsURL .= "&gid={$this->_gid}";
         }
         $lisitingURL = CRM_Utils_System::url('civicrm/contact/dedupefind', $listParamsURL);
         CRM_Utils_System::redirect($lisitingURL);
     }
     if ($this->next && $this->_mergeId) {
         $cacheKey = "merge {$this->_contactType}";
         $cacheKey .= $this->_rgid ? "_{$this->_rgid}" : '_0';
         $cacheKey .= $this->_gid ? "_{$this->_gid}" : '_0';
         $join = "LEFT JOIN civicrm_dedupe_exception de ON ( pn.entity_id1 = de.contact_id1 AND \n                                                                 pn.entity_id2 = de.contact_id2 )";
         $where = "de.id IS NULL";
         $pos = CRM_Core_BAO_PrevNextCache::getPositions($cacheKey, NULL, NULL, $this->_mergeId, $join, $where);
         if (!empty($pos) && $pos['next']['id1'] && $pos['next']['id2']) {
             $urlParam = "reset=1&cid={$pos['next']['id1']}&oid={$pos['next']['id2']}&mergeId={$pos['next']['mergeId']}&action=update";
             if ($this->_rgid) {
                 $urlParam .= "&rgid={$this->_rgid}";
             }
             if ($this->_gid) {
                 $urlParam .= "&gid={$this->_gid}";
             }
             $url = CRM_Utils_system::url('civicrm/contact/merge', $urlParam);
         }
     }
     CRM_Utils_System::redirect($url);
 }
示例#11
0
 /**
  * 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 = $this->_values;
     $params = array();
     if ($this->_action & CRM_Core_Action::ADD) {
         if (array_key_exists('TagsAndGroups', $this->_editOptions)) {
             // set group and tag defaults if any
             if ($this->_gid) {
                 $defaults['group'][$this->_gid] = 1;
             }
             if ($this->_tid) {
                 $defaults['tag'][$this->_tid] = 1;
             }
         }
         if ($this->_contactSubType) {
             $defaults['contact_sub_type'] = $this->_contactSubType;
         }
     } else {
         require_once 'CRM/Contact/BAO/Relationship.php';
         $currentEmployer = CRM_Contact_BAO_Relationship::getCurrentEmployer(array($this->_contactId));
         $defaults['current_employer_id'] = CRM_Utils_Array::value('org_id', $currentEmployer[$this->_contactId]);
         $this->assign('currentEmployer', $defaults['current_employer_id']);
         foreach ($defaults['email'] as $dontCare => &$val) {
             if (isset($val['signature_text'])) {
                 $val['signature_text_hidden'] = $val['signature_text'];
             }
             if (isset($val['signature_html'])) {
                 $val['signature_html_hidden'] = $val['signature_html'];
             }
         }
     }
     // set defaults for blocks ( custom data, address, communication preference, notes, tags and groups )
     foreach ($this->_editOptions as $name => $label) {
         if (!in_array($name, array('Address', 'Notes'))) {
             require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_Form_Edit_" . $name) . ".php";
             eval('CRM_Contact_Form_Edit_' . $name . '::setDefaultValues( $this, $defaults );');
         }
     }
     $addressValues = array();
     if (isset($defaults['address']) && is_array($defaults['address']) && !CRM_Utils_system::isNull($defaults['address'])) {
         // start of contact shared adddress defaults
         $sharedAddresses = array();
         $masterAddress = array();
         // get contact name of shared contact names
         $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']);
             } else {
                 $defaults['address'][$key]['use_shared_address'] = 0;
             }
             //check if any address is shared by any other contacts
             $masterAddress[$key] = CRM_Core_BAO_Address::checkContactSharedAddress($addressValue['id']);
         }
         $this->assign('sharedAddresses', $sharedAddresses);
         $this->assign('masterAddress', $masterAddress);
         // end of shared address defaults
         // start of parse address functionality
         // build street address, CRM-5450.
         if ($this->_parseStreetAddress) {
             $parseFields = array('street_address', 'street_number', 'street_name', 'street_unit');
             foreach ($defaults['address'] as $cnt => &$address) {
                 $streetAddress = null;
                 foreach (array('street_number', 'street_number_suffix', 'street_name', 'street_unit') as $fld) {
                     if (in_array($fld, array('street_name', 'street_unit'))) {
                         $streetAddress .= ' ';
                     }
                     $streetAddress .= CRM_Utils_Array::value($fld, $address);
                 }
                 $streetAddress = trim($streetAddress);
                 if (!empty($streetAddress)) {
                     $address['street_address'] = $streetAddress;
                 }
                 $address['street_number'] .= CRM_Utils_Array::value('street_number_suffix', $address);
                 // build array for set default.
                 foreach ($parseFields as $field) {
                     $addressValues["{$field}_{$cnt}"] = CRM_Utils_Array::value($field, $address);
                 }
                 // don't load fields, use js to populate.
                 foreach (array('street_number', 'street_name', 'street_unit') as $f) {
                     if (isset($address[$f])) {
                         unset($address[$f]);
                     }
                 }
             }
             $this->assign('allAddressFieldValues', json_encode($addressValues));
             //hack to handle show/hide address fields.
             $parsedAddress = array();
             if ($this->_contactId && CRM_Utils_Array::value('address', $_POST) && is_array($_POST['address'])) {
                 foreach ($_POST['address'] as $cnt => $values) {
                     $showField = 'streetAddress';
                     foreach (array('street_number', 'street_name', 'street_unit') as $fld) {
                         if (CRM_Utils_Array::value($fld, $values)) {
                             $showField = 'addressElements';
                             break;
                         }
                     }
                     $parsedAddress[$cnt] = $showField;
                 }
             }
             $this->assign('showHideAddressFields', $parsedAddress);
             $this->assign('loadShowHideAddressFields', empty($parsedAddress) ? false : true);
         }
         // end of parse address functionality
     }
     if (CRM_Utils_Array::value('image_URL', $defaults)) {
         list($imageWidth, $imageHeight) = getimagesize($defaults['image_URL']);
         list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight);
         $this->assign("imageWidth", $imageWidth);
         $this->assign("imageHeight", $imageHeight);
         $this->assign("imageThumbWidth", $imageThumbWidth);
         $this->assign("imageThumbHeight", $imageThumbHeight);
         $this->assign("imageURL", $defaults['image_URL']);
     }
     //set location type and country to default for each block
     $this->blockSetDefaults($defaults);
     return $defaults;
 }
示例#12
0
 /**
  * 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 = $this->_values;
     $params = array();
     if ($this->_action & CRM_Core_Action::ADD) {
         if (array_key_exists('TagsAndGroups', $this->_editOptions)) {
             // set group and tag defaults if any
             if ($this->_gid) {
                 $defaults['group'][$this->_gid] = 1;
             }
             if ($this->_tid) {
                 $defaults['tag'][$this->_tid] = 1;
             }
         }
         if ($this->_contactSubType) {
             $defaults['contact_sub_type'] = $this->_contactSubType;
         }
     } else {
         if (isset($this->_elementIndex["shared_household"])) {
             $sharedHousehold = $this->getElementValue("shared_household");
             if ($sharedHousehold) {
                 $this->assign('defaultSharedHousehold', $sharedHousehold);
             } elseif (CRM_Utils_Array::value('mail_to_household_id', $defaults)) {
                 $defaults['use_household_address'] = true;
                 $this->assign('defaultSharedHousehold', $defaults['mail_to_household_id']);
             }
             $defaults['shared_household_id'] = CRM_Utils_Array::value('mail_to_household_id', $defaults);
             if (array_key_exists(1, $defaults['address'])) {
                 $this->assign('sharedHouseholdAddress', $defaults['address'][1]['display']);
             }
         }
         require_once 'CRM/Contact/BAO/Relationship.php';
         $currentEmployer = CRM_Contact_BAO_Relationship::getCurrentEmployer(array($this->_contactId));
         $defaults['current_employer_id'] = CRM_Utils_Array::value('org_id', $currentEmployer[$this->_contactId]);
         $this->assign('currentEmployer', $defaults['current_employer_id']);
     }
     // set defaults for blocks ( custom data, address, communication preference, notes, tags and groups )
     foreach ($this->_editOptions as $name => $label) {
         if (!in_array($name, array('Address', 'Notes'))) {
             require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_Form_Edit_" . $name) . ".php";
             eval('CRM_Contact_Form_Edit_' . $name . '::setDefaultValues( $this, $defaults );');
         }
     }
     // build street address, CRM-5450.
     $addressValues = array();
     if ($this->_parseStreetAddress) {
         if (is_array($defaults['address']) && !CRM_Utils_system::isNull($defaults['address'])) {
             $parseFields = array('street_address', 'street_number', 'street_name', 'street_unit');
             foreach ($defaults['address'] as $cnt => &$address) {
                 $streetAddress = null;
                 foreach (array('street_number', 'street_number_suffix', 'street_name', 'street_unit') as $fld) {
                     if (in_array($fld, array('street_name', 'street_unit'))) {
                         $streetAddress .= ' ';
                     }
                     $streetAddress .= CRM_Utils_Array::value($fld, $address);
                 }
                 $streetAddress = trim($streetAddress);
                 if (!empty($streetAddress)) {
                     $address['street_address'] = $streetAddress;
                 }
                 $address['street_number'] .= CRM_Utils_Array::value('street_number_suffix', $address);
                 // build array for set default.
                 foreach ($parseFields as $field) {
                     $addressValues["{$field}_{$cnt}"] = CRM_Utils_Array::value($field, $address);
                 }
                 // don't load fields, use js to populate.
                 foreach (array('street_number', 'street_name', 'street_unit') as $f) {
                     if (isset($address[$f])) {
                         unset($address[$f]);
                     }
                 }
             }
         }
         $this->assign('allAddressFieldValues', json_encode($addressValues));
         //hack to handle show/hide address fields.
         $parsedAddress = array();
         if ($this->_contactId && CRM_Utils_Array::value('address', $_POST) && is_array($_POST['address'])) {
             foreach ($_POST['address'] as $cnt => $values) {
                 $showField = 'streetAddress';
                 foreach (array('street_number', 'street_name', 'street_unit') as $fld) {
                     if (CRM_Utils_Array::value($fld, $values)) {
                         $showField = 'addressElements';
                         break;
                     }
                 }
                 $parsedAddress[$cnt] = $showField;
             }
         }
         $this->assign('showHideAddressFields', $parsedAddress);
         $this->assign('loadShowHideAddressFields', empty($parsedAddress) ? false : true);
     }
     //set location type and country to default for each block
     $this->blockSetDefaults($defaults);
     return $defaults;
 }