Exemplo n.º 1
0
 /**
  * Given a permission string, check for access requirements
  *
  * @param string $str
  *   The permission to check.
  *
  * @return bool
  *   true if yes, else false
  */
 public function check($str)
 {
     $config = CRM_Core_Config::singleton();
     $translated = $this->translateJoomlaPermission($str);
     if ($translated === CRM_Core_Permission::ALWAYS_DENY_PERMISSION) {
         return FALSE;
     }
     if ($translated === CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION) {
         return TRUE;
     }
     // ensure that we are running in a joomla context
     // we've not yet figured out how to bootstrap joomla, so we should
     // not execute hooks if joomla is not loaded
     if (defined('_JEXEC')) {
         $user = JFactory::getUser();
         $api_key = CRM_Utils_Request::retrieve('api_key', 'String', $store, FALSE, NULL, 'REQUEST');
         // If we are coming from REST we don't have a user but we do have the api_key for a user.
         if ($user->id === 0 && !is_null($api_key)) {
             // This is a codeblock copied from /Civicrm/Utils/REST
             $uid = NULL;
             if (!$uid) {
                 $store = NULL;
                 $contact_id = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $api_key, 'id', 'api_key');
                 if ($contact_id) {
                     $uid = CRM_Core_BAO_UFMatch::getUFId($contact_id);
                 }
                 $user = JFactory::getUser($uid);
             }
         }
         return $user->authorise($translated[0], $translated[1]);
     } else {
         return FALSE;
     }
 }
Exemplo n.º 2
0
 static function groupContact($groupID, $contactIDs, $op)
 {
     $config = CRM_Core_Config::singleton();
     $ogID = CRM_Bridge_OG_Utils::ogID($groupID, FALSE);
     if (!$ogID) {
         return;
     }
     foreach ($contactIDs as $contactID) {
         $drupalID = CRM_Core_BAO_UFMatch::getUFId($contactID);
         if ($drupalID) {
             if ($op == 'add') {
                 $group_membership = $config->userSystem->og_membership_create($ogID, $drupalID);
             } else {
                 $group_membership = $config->userSystem->og_membership_delete($ogID, $drupalID);
             }
         }
     }
 }
 static function groupContact($groupID, $contactIDs, $op)
 {
     $ogID = CRM_Bridge_OG_Utils::ogID($groupID, FALSE);
     if (!$ogID) {
         return;
     }
     foreach ($contactIDs as $contactID) {
         $drupalID = CRM_Core_BAO_UFMatch::getUFId($contactID);
         if ($drupalID) {
             if ($op == 'add') {
                 $group_membership = og_membership_create($ogID, 'user', $drupalID, array('is_active' => 1));
                 $group_membership->save();
             } else {
                 $membership = og_get_group_membership($ogID, 'user', $drupalID);
                 if ($membership) {
                     og_membership_delete($membership->id);
                 }
             }
         }
     }
 }
Exemplo n.º 4
0
 public function preProcess()
 {
     if (!CRM_Core_Permission::check('merge duplicate contacts')) {
         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);
     $flip = CRM_Utils_Request::retrieve('flip', 'Positive', $this, FALSE);
     $this->_rgid = CRM_Utils_Request::retrieve('rgid', 'Positive', $this, FALSE);
     $this->_gid = $gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, FALSE);
     $this->_mergeId = CRM_Utils_Request::retrieve('mergeId', 'Positive', $this, FALSE);
     $this->limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this, FALSE);
     $urlParams = "reset=1&rgid={$this->_rgid}&gid={$this->_gid}&limit=" . $this->limit;
     // Sanity check
     if ($cid == $oid) {
         CRM_Core_Error::statusBounce(ts('Cannot merge a contact with itself.'));
     }
     if (!CRM_Dedupe_BAO_Rule::validateContacts($cid, $oid)) {
         CRM_Core_Error::statusBounce(ts('The selected pair of contacts are marked as non duplicates. If these records should be merged, you can remove this exception on the <a href="%1">Dedupe Exceptions</a> page.', array(1 => CRM_Utils_System::url('civicrm/dedupe/exception', 'reset=1'))));
     }
     $this->_contactType = civicrm_api3('Contact', 'getvalue', array('id' => $cid, 'return' => 'contact_type'));
     $isFromDedupeScreen = TRUE;
     if (!$this->_rgid) {
         $isFromDedupeScreen = FALSE;
         $this->_rgid = civicrm_api3('RuleGroup', 'getvalue', array('contact_type' => $this->_contactType, 'used' => 'Supervised', 'return' => 'id'));
     }
     $cacheKey = CRM_Dedupe_Merger::getMergeCacheKeyString($this->_rgid, $gid);
     $join = CRM_Dedupe_Merger::getJoinOnDedupeTable();
     $where = "de.id IS NULL";
     $pos = CRM_Core_BAO_PrevNextCache::getPositions($cacheKey, $cid, $oid, $this->_mergeId, $join, $where, $flip);
     // Block access if user does not have EDIT permissions for both contacts.
     if (!(CRM_Contact_BAO_Contact_Permission::allow($cid, CRM_Core_Permission::EDIT) && CRM_Contact_BAO_Contact_Permission::allow($oid, CRM_Core_Permission::EDIT))) {
         CRM_Utils_System::permissionDenied();
     }
     // get user info of main contact.
     $config = CRM_Core_Config::singleton();
     $config->doNotResetCache = 1;
     $viewUser = CRM_Core_Permission::check('access user profiles');
     $mainUfId = CRM_Core_BAO_UFMatch::getUFId($cid);
     $mainUser = NULL;
     if ($mainUfId) {
         // d6 compatible
         if ($config->userSystem->is_drupal == '1') {
             $mainUser = user_load($mainUfId);
         } elseif ($config->userFramework == 'Joomla') {
             $mainUser = JFactory::getUser($mainUfId);
         }
         $this->assign('mainUfId', $mainUfId);
         $this->assign('mainUfName', $mainUser ? $mainUser->name : NULL);
     }
     $flipUrl = CRM_Utils_System::url('civicrm/contact/merge', "reset=1&action=update&cid={$oid}&oid={$cid}&rgid={$this->_rgid}&gid={$gid}");
     if (!$flip) {
         $flipUrl .= '&flip=1';
     }
     $this->assign('flip', $flipUrl);
     $this->prev = $this->next = NULL;
     foreach (array('prev', 'next') as $position) {
         if (!empty($pos[$position])) {
             if ($pos[$position]['id1'] && $pos[$position]['id2']) {
                 $urlParams .= "&cid={$pos[$position]['id1']}&oid={$pos[$position]['id2']}&mergeId={$pos[$position]['mergeId']}&action=update";
                 $this->{$position} = CRM_Utils_System::url('civicrm/contact/merge', $urlParams);
                 $this->assign($position, $this->{$position});
             }
         }
     }
     // get user info of other contact.
     $otherUfId = CRM_Core_BAO_UFMatch::getUFId($oid);
     $otherUser = NULL;
     if ($otherUfId) {
         // d6 compatible
         if ($config->userSystem->is_drupal == '1') {
             $otherUser = user_load($otherUfId);
         } elseif ($config->userFramework == 'Joomla') {
             $otherUser = JFactory::getUser($otherUfId);
         }
         $this->assign('otherUfId', $otherUfId);
         $this->assign('otherUfName', $otherUser ? $otherUser->name : NULL);
     }
     $cmsUser = $mainUfId && $otherUfId ? TRUE : FALSE;
     $this->assign('user', $cmsUser);
     $session = CRM_Core_Session::singleton();
     // context fixed.
     if ($isFromDedupeScreen) {
         $browseUrl = CRM_Utils_System::url('civicrm/contact/dedupefind', $urlParams . '&action=browse');
         $session->pushUserContext($browseUrl);
     }
     $this->assign('browseUrl', empty($browseUrl) ? '' : $browseUrl);
     // 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);
     }
     $rowsElementsAndInfo = CRM_Dedupe_Merger::getRowsElementsAndInfo($cid, $oid);
     $main = $this->_mainDetails =& $rowsElementsAndInfo['main_details'];
     $other = $this->_otherDetails =& $rowsElementsAndInfo['other_details'];
     if ($main['contact_id'] != $cid) {
         CRM_Core_Error::fatal(ts('The main contact record does not exist'));
     }
     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->assign('rgid', $this->_rgid);
     $this->_cid = $cid;
     $this->_oid = $oid;
     $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('class' => 'select-rows'));
     $this->assign('mainLocBlock', json_encode($rowsElementsAndInfo['main_details']['location_blocks']));
     $this->assign('locationBlockInfo', json_encode(CRM_Dedupe_Merger::getLocationBlockInfo()));
     $this->assign('rows', $rowsElementsAndInfo['rows']);
     // add elements
     foreach ($rowsElementsAndInfo['elements'] as $element) {
         $this->addElement($element[0], $element[1], array_key_exists('2', $element) ? $element[2] : NULL, array_key_exists('3', $element) ? $element[3] : NULL, array_key_exists('4', $element) ? $element[4] : NULL, array_key_exists('5', $element) ? $element[5] : NULL);
     }
     // add related table elements
     foreach ($rowsElementsAndInfo['rel_table_elements'] as $relTableElement) {
         $element = $this->addElement($relTableElement[0], $relTableElement[1]);
         $element->setChecked(TRUE);
     }
     $this->assign('rel_tables', $rowsElementsAndInfo['rel_tables']);
     $this->assign('userContextURL', $session->readUserContext());
 }
Exemplo n.º 5
0
 /**
  * A function to build an array of information required by merge function and the merge UI.
  *
  * @param int $mainId
  *   Main contact with whom merge has to happen.
  * @param int $otherId
  *   Duplicate contact which would be deleted after merge operation.
  *
  * @return array|bool|int
  *   'main_loc_block' => Stores all location blocks associated with the 'main' contact
  */
 public static function getRowsElementsAndInfo($mainId, $otherId)
 {
     $qfZeroBug = 'e8cddb72-a257-11dc-b9cc-0016d3330ee9';
     // Fetch contacts
     foreach (array('main' => $mainId, 'other' => $otherId) as $moniker => $cid) {
         $params = array('contact_id' => $cid, 'version' => 3, 'return' => array_merge(array('display_name'), self::getContactFields()));
         $result = civicrm_api('contact', 'get', $params);
         if (empty($result['values'][$cid]['contact_type'])) {
             return FALSE;
         }
         ${$moniker} = $result['values'][$cid];
     }
     $fields = CRM_Contact_DAO_Contact::fields();
     // FIXME: there must be a better way
     foreach (array('main', 'other') as $moniker) {
         $contact =& ${$moniker};
         $preferred_communication_method = CRM_Utils_array::value('preferred_communication_method', $contact);
         $value = empty($preferred_communication_method) ? array() : $preferred_communication_method;
         $specialValues[$moniker] = array('preferred_communication_method' => $value, 'communication_style_id' => $value);
         if (!empty($contact['preferred_communication_method'])) {
             // api 3 returns pref_comm_method as an array, which breaks the lookup; so we reconstruct
             $prefCommList = is_array($specialValues[$moniker]['preferred_communication_method']) ? implode(CRM_Core_DAO::VALUE_SEPARATOR, $specialValues[$moniker]['preferred_communication_method']) : $specialValues[$moniker]['preferred_communication_method'];
             $specialValues[$moniker]['preferred_communication_method'] = CRM_Core_DAO::VALUE_SEPARATOR . $prefCommList . CRM_Core_DAO::VALUE_SEPARATOR;
         }
         $names = array('preferred_communication_method' => array('newName' => 'preferred_communication_method_display', 'groupName' => 'preferred_communication_method'));
         CRM_Core_OptionGroup::lookupValues($specialValues[$moniker], $names);
         if (!empty($contact['communication_style'])) {
             $specialValues[$moniker]['communication_style_id_display'] = $contact['communication_style'];
         }
     }
     static $optionValueFields = array();
     if (empty($optionValueFields)) {
         $optionValueFields = CRM_Core_OptionValue::getFields();
     }
     foreach ($optionValueFields as $field => $params) {
         $fields[$field]['title'] = $params['title'];
     }
     $compareFields = self::retrieveFields($main, $other);
     $rows = $elements = $relTableElements = $migrationInfo = array();
     foreach ($compareFields['contact'] as $field) {
         if ($field == 'contact_sub_type') {
             // CRM-15681 don't display sub-types in UI
             continue;
         }
         foreach (array('main', 'other') as $moniker) {
             $contact =& ${$moniker};
             $value = CRM_Utils_Array::value($field, $contact);
             if (isset($specialValues[$moniker][$field]) && is_string($specialValues[$moniker][$field])) {
                 $value = CRM_Core_DAO::VALUE_SEPARATOR . trim($specialValues[$moniker][$field], CRM_Core_DAO::VALUE_SEPARATOR) . CRM_Core_DAO::VALUE_SEPARATOR;
             }
             $label = isset($specialValues[$moniker]["{$field}_display"]) ? $specialValues[$moniker]["{$field}_display"] : $value;
             if (!empty($fields[$field]['type']) && $fields[$field]['type'] == CRM_Utils_Type::T_DATE) {
                 if ($value) {
                     $value = str_replace('-', '', $value);
                     $label = CRM_Utils_Date::customFormat($label);
                 } else {
                     $value = "null";
                 }
             } elseif (!empty($fields[$field]['type']) && $fields[$field]['type'] == CRM_Utils_Type::T_BOOLEAN) {
                 if ($label === '0') {
                     $label = ts('[ ]');
                 }
                 if ($label === '1') {
                     $label = ts('[x]');
                 }
             } elseif ($field == 'individual_prefix' || $field == 'prefix_id') {
                 $label = CRM_Utils_Array::value('individual_prefix', $contact);
                 $value = CRM_Utils_Array::value('prefix_id', $contact);
                 $field = 'prefix_id';
             } elseif ($field == 'individual_suffix' || $field == 'suffix_id') {
                 $label = CRM_Utils_Array::value('individual_suffix', $contact);
                 $value = CRM_Utils_Array::value('suffix_id', $contact);
                 $field = 'suffix_id';
             } elseif ($field == 'gender_id' && !empty($value)) {
                 $genderOptions = civicrm_api3('contact', 'getoptions', array('field' => 'gender_id'));
                 $label = $genderOptions['values'][$value];
             } elseif ($field == 'current_employer_id' && !empty($value)) {
                 $label = "{$value} (" . CRM_Contact_BAO_Contact::displayName($value) . ")";
             }
             $rows["move_{$field}"][$moniker] = $label;
             if ($moniker == 'other') {
                 //CRM-14334
                 if ($value === NULL || $value == '') {
                     $value = 'null';
                 }
                 if ($value === 0 or $value === '0') {
                     $value = $qfZeroBug;
                 }
                 if (is_array($value) && empty($value[1])) {
                     $value[1] = NULL;
                 }
                 // Display a checkbox to migrate, only if the values are different
                 if ($value != $main[$field]) {
                     $elements[] = array('advcheckbox', "move_{$field}", NULL, NULL, NULL, $value);
                 }
                 $migrationInfo["move_{$field}"] = $value;
             }
         }
         $rows["move_{$field}"]['title'] = $fields[$field]['title'];
     }
     // Handle location blocks.
     // @todo OpenID not in API yet, so is not supported here.
     // Set up useful information about the location blocks
     $locationBlocks = self::getLocationBlockInfo();
     $locations = array('main' => array(), 'other' => array());
     $mainLocBlock = array();
     // @todo This could probably be defined and used earlier
     $mergeTargets = array('main' => $mainId, 'other' => $otherId);
     foreach ($locationBlocks as $blockName => $blockInfo) {
         // Collect existing fields from both 'main' and 'other' contacts first
         // This allows us to match up location/types when building the table rows
         foreach ($mergeTargets as $moniker => $cid) {
             $cnt = 1;
             $searchParams = array('version' => 3, 'contact_id' => $cid, 'options' => array('sort' => $blockInfo['sortString']));
             $values = civicrm_api($blockName, 'get', $searchParams);
             if ($values['count']) {
                 $cnt = 0;
                 foreach ($values['values'] as $index => $value) {
                     $locations[$moniker][$blockName][$cnt] = $value;
                     // Fix address display
                     $display = '';
                     if ($blockName == 'address') {
                         CRM_Core_BAO_Address::fixAddress($value);
                         $display = CRM_Utils_Address::format($value);
                         $locations[$moniker][$blockName][$cnt]['display'] = $display;
                     }
                     // Add any 'main' contact block values to an array for the JS
                     // @todo The JS should just access the main_details to find this info?
                     if ($moniker == 'main') {
                         if ($blockInfo['hasType']) {
                             // Handle websites, no location type ID
                             // @todo Remove the need for this specific 'if'
                             if ($blockName == 'website') {
                                 $value['location_type_id'] = 0;
                             }
                             $mainLocBlock["main_" . $blockName . "_" . $value['location_type_id'] . "_" . $value[$blockInfo['hasType']]]['display'] = $value[$blockInfo['displayField']];
                             $mainLocBlock["main_" . $blockName . "_" . $value['location_type_id'] . "_" . $value[$blockInfo['hasType']]]['id'] = $value['id'];
                         } else {
                             // Get the correct display value for addresses
                             // @todo Remove the need for this if...
                             if ($blockName == 'address') {
                                 $mainLocBlock["main_" . $blockName . "_" . $value['location_type_id']]['display'] = $display;
                                 $mainLocBlock["main_" . $blockName . "_" . $value['location_type_id']]['id'] = $value['id'];
                             } else {
                                 $mainLocBlock["main_" . $blockName . "_" . $value['location_type_id']]['display'] = $value[$blockInfo['displayField']];
                                 $mainLocBlock["main_" . $blockName . "_" . $value['location_type_id']]['id'] = $value['id'];
                             }
                         }
                     }
                     $cnt++;
                 }
             }
         }
         // Now, build the table rows appropriately, based off the information on
         // the 'other' contact
         if (!empty($locations['other']) && !empty($locations['other'][$blockName])) {
             foreach ($locations['other'][$blockName] as $count => $value) {
                 $displayValue = $value[$blockInfo['displayField']];
                 // Add this value to the table rows
                 $rows["move_location_{$blockName}_{$count}"]['other'] = $displayValue;
                 // CRM-17556 Only display 'main' contact value if it's the same location + type
                 // Look it up from main values...
                 $lookupLocation = FALSE;
                 if ($blockInfo['hasLocation']) {
                     $lookupLocation = $value['location_type_id'];
                 }
                 $lookupType = FALSE;
                 if ($blockInfo['hasType']) {
                     $lookupType = $value[$blockInfo['hasType']];
                 }
                 // Hold ID of main contact's matching block
                 $mainContactBlockId = 0;
                 if (!empty($locations['main'][$blockName])) {
                     foreach ($locations['main'][$blockName] as $mainValueCheck) {
                         // No location/type, or matching location and type
                         if ((empty($lookupLocation) || $lookupLocation == $mainValueCheck['location_type_id']) && (empty($lookupType) || $lookupType == $mainValueCheck[$blockInfo['hasType']])) {
                             // Set this value as the default against the 'other' contact value
                             $rows["move_location_{$blockName}_{$count}"]['main'] = $mainValueCheck[$blockInfo['displayField']];
                             $mainContactBlockId = $mainValueCheck['id'];
                             break;
                         }
                     }
                 }
                 // Add checkbox to migrate data from 'other' to 'main'
                 $elements[] = array('advcheckbox', "move_location_{$blockName}_{$count}");
                 // Flag up this field to skipMerge function (@todo: do we need to?)
                 $migrationInfo["move_location_{$blockName}_{$count}"] = 1;
                 // Add a hidden field to store the ID of the target main contact block
                 $elements[] = array('hidden', "location[{$blockName}][{$count}][mainContactBlockId]", $mainContactBlockId);
                 // Setup variables
                 $thisTypeId = FALSE;
                 $thisLocId = FALSE;
                 // Provide a select drop-down for the location's location type
                 // eg: Home, Work...
                 $js = NULL;
                 if ($blockInfo['hasLocation']) {
                     // Load the location options for this entity
                     $locationOptions = civicrm_api3($blockName, 'getoptions', array('field' => 'location_type_id'));
                     // JS lookup 'main' contact's location (if there are any)
                     if (!empty($locations['main'][$blockName])) {
                         $js = array('onChange' => "mergeBlock('{$blockName}', this, {$count}, 'locTypeId' );");
                     }
                     $thisLocId = $value['location_type_id'];
                     // Put this field's location type at the top of the list
                     $tmpIdList = $locationOptions['values'];
                     $defaultLocId = array($thisLocId => $tmpIdList[$thisLocId]);
                     unset($tmpIdList[$thisLocId]);
                     // Add the element
                     $elements[] = array('select', "location[{$blockName}][{$count}][locTypeId]", NULL, $defaultLocId + $tmpIdList, $js);
                     // Add the relevant information to the $migrationInfo
                     // Keep location-type-id same as that of other-contact
                     // @todo Check this logic out
                     $migrationInfo['location_blocks'][$blockName][$count]['locTypeId'] = $thisLocId;
                     if ($blockName != 'address') {
                         $elements[] = array('advcheckbox', "location[{$blockName}][{$count}][operation]", NULL, ts('add new'));
                         // always use add operation
                         $migrationInfo['location_blocks'][$blockName][$count]['operation'] = 1;
                     }
                 }
                 // Provide a select drop-down for the location's type/provider
                 // eg websites: Google+, Facebook...
                 $js = NULL;
                 if ($blockInfo['hasType']) {
                     // Load the type options for this entity
                     $typeOptions = civicrm_api3($blockName, 'getoptions', array('field' => $blockInfo['hasType']));
                     // CRM-17556 Set up JS lookup of 'main' contact's value by type
                     if (!empty($locations['main'][$blockName])) {
                         $js = array('onChange' => "mergeBlock('{$blockName}', this, {$count}, 'typeTypeId' );");
                     }
                     $thisTypeId = $value[$blockInfo['hasType']];
                     // Put this field's location type at the top of the list
                     $tmpIdList = $typeOptions['values'];
                     $defaultTypeId = array($thisTypeId => $tmpIdList[$thisTypeId]);
                     unset($tmpIdList[$thisTypeId]);
                     // Add the element
                     $elements[] = array('select', "location[{$blockName}][{$count}][typeTypeId]", NULL, $defaultTypeId + $tmpIdList, $js);
                     // Add the information to the migrationInfo (@todo Why?)
                     $migrationInfo['location_blocks'][$blockName][$count]['typeTypeId'] = $thisTypeId;
                 }
                 // Set the label for this row
                 $rowTitle = $blockInfo['label'] . ' ' . ($count + 1);
                 if (!empty($thisLocId)) {
                     $rowTitle .= ' (' . $locationOptions['values'][$thisLocId] . ')';
                 }
                 if (!empty($thisTypeId)) {
                     $rowTitle .= ' (' . $typeOptions['values'][$thisTypeId] . ')';
                 }
                 $rows["move_location_{$blockName}_{$count}"]['title'] = $rowTitle;
             }
             // End loop through 'other' locations of this type
         }
         // End if 'other' location for this type exists
     }
     // End loop through each location block entity
     // add the related tables and unset the ones that don't sport any of the duplicate contact's info
     $config = CRM_Core_Config::singleton();
     $mainUfId = CRM_Core_BAO_UFMatch::getUFId($mainId);
     $mainUser = NULL;
     if ($mainUfId) {
         // d6 compatible
         if ($config->userSystem->is_drupal == '1' && function_exists($mainUser)) {
             $mainUser = user_load($mainUfId);
         } elseif ($config->userFramework == 'Joomla') {
             $mainUser = JFactory::getUser($mainUfId);
         }
     }
     $otherUfId = CRM_Core_BAO_UFMatch::getUFId($otherId);
     $otherUser = NULL;
     if ($otherUfId) {
         // d6 compatible
         if ($config->userSystem->is_drupal == '1' && function_exists($mainUser)) {
             $otherUser = user_load($otherUfId);
         } elseif ($config->userFramework == 'Joomla') {
             $otherUser = JFactory::getUser($otherUfId);
         }
     }
     $relTables = CRM_Dedupe_Merger::relTables();
     $activeRelTables = CRM_Dedupe_Merger::getActiveRelTables($otherId);
     $activeMainRelTables = CRM_Dedupe_Merger::getActiveRelTables($mainId);
     foreach ($relTables as $name => $null) {
         if (!in_array($name, $activeRelTables) && !($name == 'rel_table_users' && in_array($name, $activeMainRelTables))) {
             unset($relTables[$name]);
             continue;
         }
         $relTableElements[] = array('checkbox', "move_{$name}");
         $migrationInfo["move_{$name}"] = 1;
         $relTables[$name]['main_url'] = str_replace('$cid', $mainId, $relTables[$name]['url']);
         $relTables[$name]['other_url'] = str_replace('$cid', $otherId, $relTables[$name]['url']);
         if ($name == 'rel_table_users') {
             $relTables[$name]['main_url'] = str_replace('%ufid', $mainUfId, $relTables[$name]['url']);
             $relTables[$name]['other_url'] = str_replace('%ufid', $otherUfId, $relTables[$name]['url']);
             $find = array('$ufid', '$ufname');
             if ($mainUser) {
                 $replace = array($mainUfId, $mainUser->name);
                 $relTables[$name]['main_title'] = str_replace($find, $replace, $relTables[$name]['title']);
             }
             if ($otherUser) {
                 $replace = array($otherUfId, $otherUser->name);
                 $relTables[$name]['other_title'] = str_replace($find, $replace, $relTables[$name]['title']);
             }
         }
         if ($name == 'rel_table_memberships') {
             $elements[] = array('checkbox', "operation[move_{$name}][add]", NULL, ts('add new'));
             $migrationInfo["operation"]["move_{$name}"]['add'] = 1;
         }
     }
     foreach ($relTables as $name => $null) {
         $relTables["move_{$name}"] = $relTables[$name];
         unset($relTables[$name]);
     }
     // handle custom fields
     $mainTree = CRM_Core_BAO_CustomGroup::getTree($main['contact_type'], CRM_Core_DAO::$_nullObject, $mainId, -1, CRM_Utils_Array::value('contact_sub_type', $main));
     $otherTree = CRM_Core_BAO_CustomGroup::getTree($main['contact_type'], CRM_Core_DAO::$_nullObject, $otherId, -1, CRM_Utils_Array::value('contact_sub_type', $other));
     CRM_Core_DAO::freeResult();
     foreach ($otherTree as $gid => $group) {
         $foundField = FALSE;
         if (!isset($group['fields'])) {
             continue;
         }
         foreach ($group['fields'] as $fid => $field) {
             if (in_array($fid, $compareFields['custom'])) {
                 if (!$foundField) {
                     $rows["custom_group_{$gid}"]['title'] = $group['title'];
                     $foundField = TRUE;
                 }
                 if (!empty($mainTree[$gid]['fields'][$fid]['customValue'])) {
                     foreach ($mainTree[$gid]['fields'][$fid]['customValue'] as $valueId => $values) {
                         $rows["move_custom_{$fid}"]['main'] = CRM_Core_BAO_CustomField::displayValue($values['data'], $fid);
                     }
                 }
                 $value = "null";
                 if (!empty($otherTree[$gid]['fields'][$fid]['customValue'])) {
                     foreach ($otherTree[$gid]['fields'][$fid]['customValue'] as $valueId => $values) {
                         $rows["move_custom_{$fid}"]['other'] = CRM_Core_BAO_CustomField::displayValue($values['data'], $fid);
                         if ($values['data'] === 0 || $values['data'] === '0') {
                             $values['data'] = $qfZeroBug;
                         }
                         $value = $values['data'] ? $values['data'] : $value;
                     }
                 }
                 $rows["move_custom_{$fid}"]['title'] = $field['label'];
                 $elements[] = array('advcheckbox', "move_custom_{$fid}", NULL, NULL, NULL, $value);
                 $migrationInfo["move_custom_{$fid}"] = $value;
             }
         }
     }
     $result = array('rows' => $rows, 'elements' => $elements, 'rel_table_elements' => $relTableElements, 'main_loc_block' => $mainLocBlock, 'rel_tables' => $relTables, 'main_details' => $main, 'other_details' => $other, 'migration_info' => $migrationInfo);
     $result['main_details']['location_blocks'] = $locations['main'];
     $result['other_details']['location_blocks'] = $locations['other'];
     return $result;
 }
Exemplo n.º 6
0
 /**
  * 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()
 {
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $this->assign('id', $this->_id);
     // retrieve the group contact id, so that we can get contact id
     $gcid = CRM_Utils_Request::retrieve('gcid', 'Positive', $this);
     if (!$gcid) {
         $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, true);
     } else {
         $this->_contactId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_GroupContact', $gcid, 'contact_id');
     }
     if (!$this->_contactId) {
         CRM_Core_Error::statusBounce(ts('We could not find a contact id.'));
     }
     $this->assign('contactId', $this->_contactId);
     $path = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId);
     CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('View Contact'), 'url' => $path)));
     CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Search Results'), 'url' => self::getSearchURL())));
     // also store in session for future use
     $session =& CRM_Core_Session::singleton();
     $session->set('view.id', $this->_contactId);
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'browse');
     $this->assign('action', $this->_action);
     // check for permissions
     $this->_permission = null;
     // automatically grant permissin for users on their own record. makes
     // things easier in dashboard
     require_once 'CRM/Contact/BAO/Contact/Permission.php';
     if ($session->get('userID') == $this->_contactId) {
         $this->assign('permission', 'edit');
         $this->_permission = CRM_Core_Permission::EDIT;
     } else {
         if (CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) {
             $this->assign('permission', 'edit');
             $this->_permission = CRM_Core_Permission::EDIT;
         } else {
             if (CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::VIEW)) {
                 $this->assign('permission', 'view');
                 $this->_permission = CRM_Core_Permission::VIEW;
             } else {
                 $session->pushUserContext(CRM_Utils_System::url('civicrm', 'reset=1'));
                 CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to view this contact.'));
             }
         }
     }
     $this->getContactDetails();
     $contactImage = $this->get('contactImage');
     $displayName = $this->get('displayName');
     $contactType = $this->get('contactType');
     $contactSubtype = $this->get('contactSubType');
     $contactImageUrl = $this->get('contactImageUrl');
     $this->assign('displayName', $displayName);
     // see if other modules want to add a link activtity bar
     require_once 'CRM/Utils/Hook.php';
     $hookLinks = CRM_Utils_Hook::links('view.contact.activity', 'Contact', $this->_contactId);
     if (is_array($hookLinks)) {
         $this->assign('hookLinks', $hookLinks);
     }
     CRM_Utils_System::setTitle($displayName, $contactImage . ' ' . $displayName);
     CRM_Utils_Recent::add($displayName, CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId), $this->_contactId, $contactType, $this->_contactId, $displayName, $contactImageUrl, $contactSubtype);
     //display OtherActivity link
     $otherAct = CRM_Core_PseudoConstant::activityType(false);
     $activityNum = count($otherAct);
     $this->assign('showOtherActivityLink', $activityNum);
     $config =& CRM_Core_Config::singleton();
     require_once 'CRM/Core/BAO/UFMatch.php';
     if ($uid = CRM_Core_BAO_UFMatch::getUFId($this->_contactId)) {
         if ($config->userFramework == 'Drupal') {
             $url = CRM_Utils_System::url('user/' . $uid);
         } else {
             if ($config->userFramework == 'Joomla') {
                 $url = $config->userFrameworkBaseURL . 'index2.php?option=com_users&view=user&task=edit&cid[]=' . $uid;
             } else {
                 $url = null;
             }
         }
         $this->assign('url', $url);
     }
     if (CRM_Core_Permission::check('access Contact Dashboard')) {
         $dashboardURL = CRM_Utils_System::url('civicrm/user', "reset=1&id={$this->_contactId}");
         $this->assign('dashboardURL', $dashboardURL);
     }
     if ($contactType == 'Organization' && CRM_Core_Permission::check('administer Multiple Organizations')) {
         require_once 'CRM/Contact/BAO/GroupOrganization.php';
         //check is any relationship between the organization and groups
         $groupOrg = CRM_Contact_BAO_GroupOrganization::hasGroupAssociated($this->_contactId);
         if ($groupOrg) {
             $groupOrganizationUrl = CRM_Utils_System::url('civicrm/group', "reset=1&oid={$this->_contactId}");
             $this->assign('groupOrganizationUrl', $groupOrganizationUrl);
         }
     }
 }
Exemplo n.º 7
0
Arquivo: REST.php Projeto: kidaa30/yes
 /**
  * @return array|NULL
  *   NULL if execution should proceed; array if the response is already known
  */
 public function loadCMSBootstrap()
 {
     $requestParams = CRM_Utils_Request::exportValues();
     $q = CRM_Utils_array::value('q', $requestParams);
     $args = explode('/', $q);
     // Proceed with bootstrap for "?entity=X&action=Y"
     // Proceed with bootstrap for "?q=civicrm/X/Y" but not "?q=civicrm/ping"
     if (!empty($q)) {
         if (count($args) == 2 && $args[1] == 'ping') {
             return NULL;
             // this is pretty wonky but maybe there's some reason I can't see
         }
         if (count($args) != 3) {
             return self::error('ERROR: Malformed REST path');
         }
         if ($args[0] != 'civicrm') {
             return self::error('ERROR: Malformed REST path');
         }
         // Therefore we have reasonably well-formed "?q=civicrm/X/Y"
     }
     if (!CRM_Utils_System::authenticateKey(FALSE)) {
         // FIXME: At time of writing, this doesn't actually do anything because
         // authenticateKey abends, but that's a bad behavior which sends a
         // malformed response.
         return self::error('Failed to authenticate key');
     }
     $uid = NULL;
     if (!$uid) {
         $store = NULL;
         $api_key = CRM_Utils_Request::retrieve('api_key', 'String', $store, FALSE, NULL, 'REQUEST');
         if (empty($api_key)) {
             return self::error("FATAL: mandatory param 'api_key' (user key) missing");
         }
         $contact_id = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $api_key, 'id', 'api_key');
         if ($contact_id) {
             $uid = CRM_Core_BAO_UFMatch::getUFId($contact_id);
         }
     }
     if ($uid) {
         CRM_Utils_System::loadBootStrap(array('uid' => $uid), TRUE, FALSE);
         return NULL;
     } else {
         return self::error('ERROR: No CMS user associated with given api-key');
     }
 }
Exemplo n.º 8
0
 function preProcess()
 {
     if (!CRM_Core_Permission::check('merge duplicate contacts')) {
         CRM_Core_Error::fatal(ts('You do not have access to this page'));
     }
     $rows = array();
     $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
     $oid = CRM_Utils_Request::retrieve('oid', 'Positive', $this, TRUE);
     $flip = CRM_Utils_Request::retrieve('flip', 'Positive', $this, FALSE);
     $this->_rgid = $rgid = CRM_Utils_Request::retrieve('rgid', 'Positive', $this, FALSE);
     $this->_gid = $gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, FALSE);
     $this->_mergeId = CRM_Utils_Request::retrieve('mergeId', 'Positive', $this, FALSE);
     if (!CRM_Dedupe_BAO_Rule::validateContacts($cid, $oid)) {
         CRM_Core_Error::statusBounce(ts('The selected pair of contacts are marked as non duplicates. If these records should be merged, you can remove this exception on the <a href=\'%1\'>Dedupe Exceptions</a> page.', array(1 => CRM_Utils_System::url('civicrm/dedupe/exception', 'reset=1'))));
     }
     //load cache mechanism
     $contactType = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'contact_type');
     $cacheKey = "merge {$contactType}";
     $cacheKey .= $rgid ? "_{$rgid}" : '_0';
     $cacheKey .= $gid ? "_{$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, $cid, $oid, $this->_mergeId, $join, $where, $flip);
     // Block access if user does not have EDIT permissions for both contacts.
     if (!(CRM_Contact_BAO_Contact_Permission::allow($cid, CRM_Core_Permission::EDIT) && CRM_Contact_BAO_Contact_Permission::allow($oid, CRM_Core_Permission::EDIT))) {
         CRM_Utils_System::permissionDenied();
     }
     // get user info of main contact.
     $config = CRM_Core_Config::singleton();
     $config->doNotResetCache = 1;
     $viewUser = CRM_Core_Permission::check('access user profiles');
     $mainUfId = CRM_Core_BAO_UFMatch::getUFId($cid);
     $mainUser = NULL;
     if ($mainUfId) {
         // d6 compatible
         if ($config->userSystem->is_drupal == '1') {
             $mainUser = user_load($mainUfId);
         } elseif ($config->userFramework == 'Joomla') {
             $mainUser = JFactory::getUser($mainUfId);
         }
         $this->assign('mainUfId', $mainUfId);
         $this->assign('mainUfName', $mainUser ? $mainUser->name : NULL);
     }
     $flipUrl = CRM_Utils_System::url('civicrm/contact/merge', "reset=1&action=update&cid={$oid}&oid={$cid}&rgid={$rgid}&gid={$gid}");
     if (!$flip) {
         $flipUrl .= '&flip=1';
     }
     $this->assign('flip', $flipUrl);
     $this->prev = $this->next = NULL;
     foreach (array('prev', 'next') as $position) {
         if (!empty($pos[$position])) {
             if ($pos[$position]['id1'] && $pos[$position]['id2']) {
                 $urlParam = "reset=1&cid={$pos[$position]['id1']}&oid={$pos[$position]['id2']}&mergeId={$pos[$position]['mergeId']}&action=update";
                 if ($rgid) {
                     $urlParam .= "&rgid={$rgid}";
                 }
                 if ($gid) {
                     $urlParam .= "&gid={$gid}";
                 }
                 $this->{$position} = CRM_Utils_System::url('civicrm/contact/merge', $urlParam);
                 $this->assign($position, $this->{$position});
             }
         }
     }
     // get user info of other contact.
     $otherUfId = CRM_Core_BAO_UFMatch::getUFId($oid);
     $otherUser = NULL;
     if ($otherUfId) {
         // d6 compatible
         if ($config->userSystem->is_drupal == '1') {
             $otherUser = user_load($otherUfId);
         } elseif ($config->userFramework == 'Joomla') {
             $otherUser = JFactory::getUser($otherUfId);
         }
         $this->assign('otherUfId', $otherUfId);
         $this->assign('otherUfName', $otherUser ? $otherUser->name : NULL);
     }
     $cmsUser = $mainUfId && $otherUfId ? TRUE : FALSE;
     $this->assign('user', $cmsUser);
     $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/contact/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);
     }
     $rowsElementsAndInfo = CRM_Dedupe_Merger::getRowsElementsAndInfo($cid, $oid);
     $main =& $rowsElementsAndInfo['main_details'];
     $other =& $rowsElementsAndInfo['other_details'];
     if ($main['contact_id'] != $cid) {
         CRM_Core_Error::fatal(ts('The main contact record does not exist'));
     }
     if ($other['contact_id'] != $oid) {
         CRM_Core_Error::fatal(ts('The other contact record does not exist'));
     }
     $subtypes = CRM_Contact_BAO_ContactType::subTypePairs(NULL, TRUE, '');
     $this->assign('contact_type', $main['contact_type']);
     if (!empty($main['contact_sub_type'])) {
         $this->assign('main_contact_subtype', CRM_Utils_Array::value('contact_sub_type', $subtypes[$main['contact_sub_type'][0]]));
     }
     if (!empty($other['contact_sub_type'])) {
         $this->assign('other_contact_subtype', CRM_Utils_Array::value('contact_sub_type', $subtypes[$other['contact_sub_type'][0]]));
     }
     $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->assign('rgid', $rgid);
     $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);"));
     $this->assign('mainLocBlock', json_encode($rowsElementsAndInfo['main_loc_block']));
     $this->assign('rows', $rowsElementsAndInfo['rows']);
     $this->_locBlockIds = array('main' => $rowsElementsAndInfo['main_details']['loc_block_ids'], 'other' => $rowsElementsAndInfo['other_details']['loc_block_ids']);
     // add elements
     foreach ($rowsElementsAndInfo['elements'] as $element) {
         $this->addElement($element[0], $element[1], array_key_exists('2', $element) ? $element[2] : NULL, array_key_exists('3', $element) ? $element[3] : NULL, array_key_exists('4', $element) ? $element[4] : NULL, array_key_exists('5', $element) ? $element[5] : NULL);
     }
     // add related table elements
     foreach ($rowsElementsAndInfo['rel_table_elements'] as $relTableElement) {
         $element = $this->addElement($relTableElement[0], $relTableElement[1]);
         $element->setChecked(TRUE);
     }
     $this->assign('rel_tables', $rowsElementsAndInfo['rel_tables']);
     $this->assign('userContextURL', $session->readUserContext());
 }
 /**
  * Set variables up before form is built.
  *
  * @return void
  */
 public function preProcess()
 {
     $session = CRM_Core_Session::singleton();
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $contributionParams = $requestParams = $_REQUEST;
     $contactID = $session->get('userID');
     if ($contactID && empty($contributionParams['email'])) {
         $emailDetails = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID);
         if (!empty($emailDetails)) {
             $contributionParams['email'] = $emailDetails[1];
             // for email to be prefilled
             $this->assign('email', $emailDetails[1]);
         }
     }
     $pageConfig = civicrm_api3('ContributionPage', 'getsingle', array('id' => $this->_id));
     if (is_array($pageConfig['payment_processor'])) {
         CRM_Core_Error::fatal(ts('Multiple payment processors not supported with quick donate.'));
     }
     $processorDetails = CRM_Financial_BAO_PaymentProcessor::getPayment($pageConfig['payment_processor'], 'live');
     //MV: get amount details if other amount enabled for contribution page.
     if ($pageConfig['amount_block_is_active']) {
         $sql = "SELECT cpfv.amount, cpfv.is_default, cpfv.weight \n        FROM civicrm_price_field_value cpfv \n        INNER JOIN civicrm_price_field cpf ON (cpf.id = cpfv.price_field_id)\n        INNER JOIN civicrm_price_set_entity cpse ON (cpse.price_set_id = cpf.price_set_id)\n        WHERE cpse.entity_id = %1 AND cpf.name = 'contribution_amount'\n      ";
         $dao = CRM_Core_DAO::executeQuery($sql, array(1 => array($pageConfig['id'], 'Integer')));
         $amount = 0;
         while ($dao->fetch()) {
             if ($dao->weight == 1 || $dao->is_default == 1) {
                 $amount = $dao->amount;
             }
         }
     }
     $pageConfig['default_amount'] = $amount ? $amount : $pageConfig['min_amount'];
     $pageConfig['currency_symbol'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_Currency', $pageConfig['currency'], 'symbol', 'name');
     $this->assign('pageConfig', $pageConfig);
     $this->assign('key', $processorDetails['password']);
     $this->assign('currency', strtolower($pageConfig['currency']));
     if (!empty($requestParams['stripe_token'])) {
         //FIXME: could go in post process
         if (!$contributionParams['email']) {
             CRM_Core_Error::fatal(ts('Email address is required'));
         }
         $contributionParams['financial_type_id'] = $pageConfig['financial_type_id'];
         if (!$contactID) {
             $contactParams = array('email' => $contributionParams['email'], 'contact_type' => 'Individual');
             $dedupeParams = CRM_Dedupe_Finder::formatParams($contactParams, 'Individual');
             $dedupeParams['check_permission'] = FALSE;
             $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
             // if we find more than one contact, use the first one
             $contactID = CRM_Utils_Array::value(0, $ids);
             if (!$contactID) {
                 $cont = civicrm_api3('Contact', 'create', $contactParams);
                 $contactID = $cont['id'];
             }
         }
         $contributionParams['contact_id'] = $contactID;
         $contributionParams['payment_processor_id'] = $pageConfig['payment_processor'];
         $contributionParams['currencyID'] = $pageConfig['currency'];
         //gift aid
         //get gift aid custom field id
         $sqlCF = "SELECT cf.id \n      FROM civicrm_custom_field cf \n      INNER JOIN civicrm_custom_group cg ON (cg.id = cf.custom_group_id) \n      WHERE cg.name = %1 AND cf.name = %2";
         $sqlCFParams = array(1 => array(self::C_CUSTOM_GROUP_GIFT_AID, 'String'), 2 => array(self::C_CUSTOM_FIELD_GIFT_AID, 'String'));
         $cfId = CRM_Core_DAO::singleValueQuery($sqlCF, $sqlCFParams);
         if ($cfId && $contributionParams['donation_form']['gift_aid']) {
             $contributionParams["custom_{$cfId}"] = 1;
         }
         //gift aid end
         //campaign
         if ($pageConfig['campaign_id']) {
             $contributionParams['campaign_id'] = $pageConfig['campaign_id'];
         }
         try {
             $result = civicrm_api3('Contribution', 'transact', $contributionParams);
         } catch (CiviCRM_API3_Exception $e) {
             $error = $e->getMessage();
             $this->assign('error', $error);
             CRM_Utils_System::setTitle(ts('Oops! There was a problem'));
         }
         if (!empty($result['error'])) {
             $this->assign('error', $result['error']);
             CRM_Utils_System::setTitle(ts('Oops! There was a problem'));
         } else {
             if ($result) {
                 $contributionID = $result['id'];
                 $contactID = $result['values'][$contributionID]['contact_id'];
                 // Send receipt
                 civicrm_api3('contribution', 'sendconfirmation', array('id' => $contributionID) + $pageConfig);
                 CRM_Utils_System::setTitle(ts('Thank you'));
                 $this->assign('status', 'thankyou');
                 $profileID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'Supporter Profile', 'id', 'title');
                 // Link (button) for users to create their own Personal Campaign page
                 if ($profileID && !$session->get('userID')) {
                     $ufId = CRM_Core_BAO_UFMatch::getUFId($contactID);
                     if ($ufId) {
                         $config = CRM_Core_Config::singleton();
                         $loginURL = $config->userSystem->getLoginURL();
                         $this->assign('loginURL', $loginURL);
                     } else {
                         $linkTextUrl = CRM_Utils_System::url('civicrm/profile/create', "gid={$profileID}&reset=1", FALSE, NULL, TRUE);
                         $this->assign('linkTextUrl', $linkTextUrl);
                     }
                 }
                 //redirect if the logged in user
                 if ($session->get('userID')) {
                     $urlParams = array('pageId' => $this->_id, 'component' => 'contribute', 'reset' => 1);
                     $sql = "SELECT pcp.id FROM civicrm_pcp pcp \n          INNER JOIN  civicrm_pcp_block cpb ON (cpb.id = pcp.pcp_block_id)\n          WHERE cpb.entity_id = %1 AND pcp.contact_id = %2\n          ";
                     $sqlparams = array(1 => array($pageConfig['id'], 'Integer'), 2 => array($contactID, 'Integer'));
                     $pcpId = CRM_Core_DAO::singleValueQuery($sql, $sqlparams);
                     if ($pcpId) {
                         $urlParams['id'] = $pcpId;
                     }
                     $url = CRM_Utils_System::url('civicrm/pcp/setup', $urlParams);
                     CRM_Utils_System::redirect($url);
                 }
             }
         }
     } else {
         if (!empty($requestParams['_qf_Main_display'])) {
             //$this->assign('error', $error);
             CRM_Utils_System::setTitle(ts('Oops! There was a problem'));
         } else {
             $this->assign('status', 'quickdonate');
             CRM_Core_Resources::singleton()->addStyleFile('uk.co.vedaconsulting.quickdonate', 'css/quickdonatebox.css');
         }
     }
 }
Exemplo n.º 10
0
 /**
  * @inheritDoc
  */
 public function getUserRecordUrl($contactID)
 {
     $uid = CRM_Core_BAO_UFMatch::getUFId($contactID);
     $userRecordUrl = NULL;
     // if logged in user is super user, then he can view other users joomla profile
     if (JFactory::getUser()->authorise('core.admin')) {
         return CRM_Core_Config::singleton()->userFrameworkBaseURL . "index.php?option=com_users&view=user&task=user.edit&id=" . $uid;
     } elseif (CRM_Core_Session::singleton()->get('userID') == $contactID) {
         return CRM_Core_Config::singleton()->userFrameworkBaseURL . "index.php?option=com_admin&view=profile&layout=edit&id=" . $uid;
     }
 }
/**
 * Implements hook_civicrm_tabs().
 */
function woocommercecivicrm_civicrm_tabs(&$tabs, $cid)
{
    $uid = CRM_Core_BAO_UFMatch::getUFId($cid);
    if (empty($uid)) {
        return;
    }
    $orders = _woocommercecivicrm_customer_orders($uid);
    //$history = woocommerce_civicrm_contact_transaction($uid, FALSE);
    //$count = count($history['orders']['#rows']);
    $url = CRM_Utils_System::url('civicrm/woocommerce/view/purchases', "reset=1&uid={$uid}&snippet=1&force=1");
    $tabs[] = array('id' => 'woocommerce-orders', 'url' => $url, 'title' => 'Orders', 'count' => count($orders), 'weight' => 99);
}
Exemplo n.º 12
0
 /**
  * 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()
 {
     // process url params
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $this->assign('id', $this->_id);
     $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this);
     //validate the qfKey
     if (!CRM_Utils_Rule::qfKey($qfKey)) {
         $qfKey = NULL;
     }
     $this->assign('searchKey', $qfKey);
     // retrieve the group contact id, so that we can get contact id
     $gcid = CRM_Utils_Request::retrieve('gcid', 'Positive', $this);
     if (!$gcid) {
         $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
     } else {
         $this->_contactId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_GroupContact', $gcid, 'contact_id');
     }
     if (!$this->_contactId) {
         CRM_Core_Error::statusBounce(ts('We could not find a contact id.'), CRM_Utils_System::url('civicrm/dashboard', 'reset=1'));
     }
     // ensure that the id does exist
     if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'id') != $this->_contactId) {
         CRM_Core_Error::statusBounce(ts('A Contact with that ID does not exist: %1', array(1 => $this->_contactId)), CRM_Utils_System::url('civicrm/dashboard', 'reset=1'));
     }
     $this->assign('contactId', $this->_contactId);
     // see if we can get prev/next positions from qfKey
     $navContacts = array('prevContactID' => NULL, 'prevContactName' => NULL, 'nextContactID' => NULL, 'nextContactName' => NULL, 'nextPrevError' => 0);
     if ($qfKey) {
         $pos = CRM_Core_BAO_PrevNextCache::getPositions("civicrm search {$qfKey}", $this->_contactId, $this->_contactId);
         $found = FALSE;
         if (isset($pos['prev'])) {
             $navContacts['prevContactID'] = $pos['prev']['id1'];
             $navContacts['prevContactName'] = $pos['prev']['data'];
             $found = TRUE;
         }
         if (isset($pos['next'])) {
             $navContacts['nextContactID'] = $pos['next']['id1'];
             $navContacts['nextContactName'] = $pos['next']['data'];
             $found = TRUE;
         }
         if (!$found) {
             // seems like we did not find any contacts
             // maybe due to bug CRM-9096
             // however we should account for 1 contact results (which dont have prev next)
             if (!$pos['foundEntry']) {
                 $navContacts['nextPrevError'] = 1;
             }
         }
     }
     $this->assign($navContacts);
     $path = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId);
     CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('View Contact'), 'url' => $path)));
     CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Search Results'), 'url' => self::getSearchURL())));
     if ($image_URL = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'image_URL')) {
         //CRM-7265 --time being fix.
         $config = CRM_Core_Config::singleton();
         $image_URL = str_replace('https://', 'http://', $image_URL);
         if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enableSSL')) {
             $image_URL = str_replace('http://', 'https://', $image_URL);
         }
         list($imageWidth, $imageHeight) = getimagesize($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", $image_URL);
     }
     // also store in session for future use
     $session = CRM_Core_Session::singleton();
     $session->set('view.id', $this->_contactId);
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
     $this->assign('action', $this->_action);
     // check logged in user permission
     self::checkUserPermission($this);
     list($displayName, $contactImage, $contactType, $contactSubtype, $contactImageUrl) = self::getContactDetails($this->_contactId);
     $this->assign('displayName', $displayName);
     $this->set('contactType', $contactType);
     $this->set('contactSubtype', $contactSubtype);
     // see if other modules want to add a link activtity bar
     $hookLinks = CRM_Utils_Hook::links('view.contact.activity', 'Contact', $this->_contactId, CRM_Core_DAO::$_nullObject, CRM_Core_DAO::$_nullObject);
     if (is_array($hookLinks)) {
         $this->assign('hookLinks', $hookLinks);
     }
     // add to recently viewed block
     $isDeleted = (bool) CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'is_deleted');
     $recentOther = array('imageUrl' => $contactImageUrl, 'subtype' => $contactSubtype, 'isDeleted' => $isDeleted);
     if ($session->get('userID') == $this->_contactId || CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) {
         $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/add', "reset=1&action=update&cid={$this->_contactId}");
     }
     if ($session->get('userID') != $this->_contactId && CRM_Core_Permission::check('delete contacts') && !$isDeleted) {
         $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/delete', "reset=1&delete=1&cid={$this->_contactId}");
     }
     CRM_Utils_Recent::add($displayName, CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactId}"), $this->_contactId, $contactType, $this->_contactId, $displayName, $recentOther);
     $this->assign('isDeleted', $isDeleted);
     // set page title
     self::setTitle($this->_contactId, $isDeleted);
     $config = CRM_Core_Config::singleton();
     $uid = CRM_Core_BAO_UFMatch::getUFId($this->_contactId);
     if ($uid) {
         // To do: we should also allow drupal users with CRM_Core_Permission::check( 'view user profiles' ) true to access $userRecordUrl
         // but this is currently returning false regardless of permission set for the role. dgg
         if ($config->userSystem->is_drupal == '1' && ($session->get('userID') == $this->_contactId || CRM_Core_Permission::check('administer users'))) {
             $userRecordUrl = CRM_Utils_System::url('user/' . $uid);
         } elseif ($config->userFramework == 'Joomla') {
             $userRecordUrl = NULL;
             // if logged in user is super user, then he can view other users joomla profile
             if (JFactory::getUser()->authorise('core.admin')) {
                 $userRecordUrl = $config->userFrameworkBaseURL . "index.php?option=com_users&view=user&task=user.edit&id=" . $uid;
             } elseif ($session->get('userID') == $this->_contactId) {
                 $userRecordUrl = $config->userFrameworkBaseURL . "index.php?option=com_admin&view=profile&layout=edit&id=" . $uid;
             }
         } else {
             $userRecordUrl = NULL;
         }
         $this->assign('userRecordUrl', $userRecordUrl);
         $this->assign('userRecordId', $uid);
     } elseif ($config->userSystem->is_drupal == '1' && CRM_Core_Permission::check('administer users') || $config->userFramework == 'Joomla' && JFactory::getUser()->authorise('core.create', 'com_users')) {
         $userAddUrl = CRM_Utils_System::url('civicrm/contact/view/useradd', 'reset=1&action=add&cid=' . $this->_contactId);
         $this->assign('userAddUrl', $userAddUrl);
     }
     if (CRM_Core_Permission::check('access Contact Dashboard')) {
         $dashboardURL = CRM_Utils_System::url('civicrm/user', "reset=1&id={$this->_contactId}");
         $this->assign('dashboardURL', $dashboardURL);
     }
     if ($contactType == 'Organization' && CRM_Core_Permission::check('administer Multiple Organizations') && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, 'is_enabled')) {
         //check is any relationship between the organization and groups
         $groupOrg = CRM_Contact_BAO_GroupOrganization::hasGroupAssociated($this->_contactId);
         if ($groupOrg) {
             $groupOrganizationUrl = CRM_Utils_System::url('civicrm/group', "reset=1&oid={$this->_contactId}");
             $this->assign('groupOrganizationUrl', $groupOrganizationUrl);
         }
     }
 }
Exemplo n.º 13
0
 /**
  * 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);
     CRM_Contact_BAO_Contact::resolveDefaults($defaults);
     if (CRM_Utils_Array::value('gender_id', $defaults)) {
         $gender = CRM_Core_PseudoConstant::gender();
         $defaults['gender_display'] = $gender[CRM_Utils_Array::value('gender_id', $defaults)];
     }
     // get the list of all the categories
     $tag =& CRM_Core_PseudoConstant::tag();
     // get categories for the contact id
     require_once 'CRM/Core/BAO/EntityTag.php';
     $entityTag =& CRM_Core_BAO_EntityTag::getTag('civicrm_contact', $this->_contactId);
     if ($entityTag) {
         $categories = array();
         foreach ($entityTag as $key) {
             $categories[] = $tag[$key];
         }
         $defaults['contactTag'] = implode(', ', $categories);
     }
     $defaults['privacy_values'] = CRM_Core_SelectValues::privacy();
     $this->assign($defaults);
     $this->setShowHide($defaults);
     // get the contributions, new style of doing stuff
     // do the below only if the person has access to contributions
     $config =& CRM_Core_Config::singleton();
     if (CRM_Utils_System::accessCiviContribute()) {
         $this->assign('accessContribution', true);
         $controller =& new CRM_Core_Controller_Simple('CRM_Contribute_Form_Search', ts('Contributions'), $this->_action);
         $controller->setEmbedded(true);
         $controller->reset();
         $controller->set('limit', 3);
         $controller->set('force', 1);
         $controller->set('cid', $this->_contactId);
         $controller->set('context', 'basic');
         $controller->process();
         $controller->run();
     } else {
         $this->assign('accessContribution', false);
     }
     //add link to CMS user
     if ($uid = CRM_Core_BAO_UFMatch::getUFId($this->_contactId)) {
         if ($config->userFramework == 'Drupal') {
             $url = CRM_Utils_System::url('user/' . $uid);
         } else {
             //$url = CRM_Utils_System::url( 'option=com_users&task=editA&hidemainmenu=1&id=' . $uid );
             $url = $config->userFrameworkBaseURL . 'index2.php?option=com_users&task=editA&hidemainmenu=1&id=' . $uid;
         }
         $this->assign('url', $url);
     }
 }
 /**
  * Update a WP user when a CiviCRM contact is updated
  *
  * @param string $op The type of database operation
  * @param string $objectName The type of object
  * @param integer $objectId The ID of the object
  * @param object $objectRef The object
  * @return void
  */
 public function civi_contact_updated($op, $objectName, $objectId, $objectRef)
 {
     // target our operation
     if ($op != 'edit') {
         return;
     }
     // target our object type
     if ($objectName != 'Individual') {
         return;
     }
     $this->_debug(array('function' => 'civi_contact_updated', 'op' => $op, 'objectName' => $objectName, 'objectId' => $objectId, 'objectRef' => $objectRef));
     // check if we have a contact email
     if (!isset($objectRef->email[0]->email)) {
         // no, init CiviCRM to get WP user ID
         if (!civi_wp()->initialize()) {
             return;
         }
         // make sure Civi file is included
         require_once 'CRM/Core/BAO/UFMatch.php';
         // search using Civi's logic
         $user_id = CRM_Core_BAO_UFMatch::getUFId($objectId);
         // kick out if we didn't get one
         if (empty($user_id)) {
             return;
         }
     } else {
         // yes, use it to get WP user
         $user = get_user_by('email', $objectRef->email[0]->email);
         // bail if not a WP user
         if (!$user instanceof WP_User) {
             return;
         }
         // assign ID
         $user_id = $user->ID;
     }
     // update first name
     update_user_meta($user_id, 'first_name', $objectRef->first_name);
     // update last name
     update_user_meta($user_id, 'last_name', $objectRef->last_name);
     // compatibility with BP XProfile WordPress User Sync plugin
     if (defined('BP_XPROFILE_WP_USER_SYNC_VERSION')) {
         // access object
         global $bp_xprofile_wordpress_user_sync;
         // call the relevant sync method
         $bp_xprofile_wordpress_user_sync->intercept_wp_user_update($user_id);
     }
     // avoid getting WP user unless we're debugging
     if (CIVICRM_WP_PROFILE_SYNC_DEBUG) {
         // for debugging, let get WP user
         $user = new WP_User($user_id);
         $this->_debug(array('user' => $user, 'first_name' => $user->first_name, 'last_name' => $user->last_name));
     }
 }
Exemplo n.º 15
0
 /**
  * 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()
 {
     // process url params
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $this->assign('id', $this->_id);
     // retrieve the group contact id, so that we can get contact id
     $gcid = CRM_Utils_Request::retrieve('gcid', 'Positive', $this);
     if (!$gcid) {
         $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, true);
     } else {
         $this->_contactId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_GroupContact', $gcid, 'contact_id');
     }
     if (!$this->_contactId) {
         CRM_Core_Error::statusBounce(ts('We could not find a contact id.'));
     }
     $this->assign('contactId', $this->_contactId);
     $path = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId);
     CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('View Contact'), 'url' => $path)));
     CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Search Results'), 'url' => self::getSearchURL())));
     // also store in session for future use
     $session =& CRM_Core_Session::singleton();
     $session->set('view.id', $this->_contactId);
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'browse');
     $this->assign('action', $this->_action);
     // check logged in url permission
     self::checkUserPermission($this);
     list($displayName, $contactImage, $contactType, $contactSubtype, $contactImageUrl) = $this->getContactDetails();
     $this->assign('displayName', $displayName);
     $this->set('contactType', $contactType);
     $this->set('contactSubtype', $contactSubtype);
     // see if other modules want to add a link activtity bar
     require_once 'CRM/Utils/Hook.php';
     $hookLinks = CRM_Utils_Hook::links('view.contact.activity', 'Contact', $this->_contactId);
     if (is_array($hookLinks)) {
         $this->assign('hookLinks', $hookLinks);
     }
     // set page title
     CRM_Utils_System::setTitle($displayName, $contactImage . ' ' . $displayName);
     // add to recently viewed block
     CRM_Utils_Recent::add($displayName, CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId), $this->_contactId, $contactType, $this->_contactId, $displayName, $contactImageUrl, $contactSubtype);
     $config = CRM_Core_Config::singleton();
     require_once 'CRM/Core/BAO/UFMatch.php';
     if ($uid = CRM_Core_BAO_UFMatch::getUFId($this->_contactId)) {
         if ($config->userFramework == 'Drupal') {
             $url = CRM_Utils_System::url('user/' . $uid);
         } else {
             if ($config->userFramework == 'Joomla') {
                 $url = $config->userFrameworkBaseURL . 'index2.php?option=com_users&view=user&task=edit&cid[]=' . $uid;
             } else {
                 $url = null;
             }
         }
         $this->assign('url', $url);
     }
     if (CRM_Core_Permission::check('access Contact Dashboard')) {
         $dashboardURL = CRM_Utils_System::url('civicrm/user', "reset=1&id={$this->_contactId}");
         $this->assign('dashboardURL', $dashboardURL);
     }
     if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE && $contactType == 'Organization' && CRM_Core_Permission::check('administer Multiple Organizations')) {
         require_once 'CRM/Contact/BAO/GroupOrganization.php';
         //check is any relationship between the organization and groups
         $groupOrg = CRM_Contact_BAO_GroupOrganization::hasGroupAssociated($this->_contactId);
         if ($groupOrg) {
             $groupOrganizationUrl = CRM_Utils_System::url('civicrm/group', "reset=1&oid={$this->_contactId}");
             $this->assign('groupOrganizationUrl', $groupOrganizationUrl);
         }
     }
 }
Exemplo n.º 16
0
 /**
  * @inheritDoc
  */
 public function getUserRecordUrl($contactID)
 {
     $uid = CRM_Core_BAO_UFMatch::getUFId($contactID);
     if (CRM_Core_Session::singleton()->get('userID') == $contactID || CRM_Core_Permission::checkAnyPerm(array('cms:administer users', 'cms:view user account'))) {
         return CRM_Utils_System::url('user/' . $uid);
     }
 }
Exemplo n.º 17
0
 /**
  * A function to build an array of information required by merge function and the merge UI.
  *
  * @param int $mainId
  *   Main contact with whom merge has to happen.
  * @param int $otherId
  *   Duplicate contact which would be deleted after merge operation.
  *
  * @return array|bool|int
  */
 public static function getRowsElementsAndInfo($mainId, $otherId)
 {
     $qfZeroBug = 'e8cddb72-a257-11dc-b9cc-0016d3330ee9';
     // Fetch contacts
     foreach (array('main' => $mainId, 'other' => $otherId) as $moniker => $cid) {
         $params = array('contact_id' => $cid, 'version' => 3, 'return' => array_merge(array('display_name'), self::getContactFields()));
         $result = civicrm_api('contact', 'get', $params);
         if (empty($result['values'][$cid]['contact_type'])) {
             return FALSE;
         }
         ${$moniker} = $result['values'][$cid];
     }
     static $fields = array();
     if (empty($fields)) {
         $fields = CRM_Contact_DAO_Contact::fields();
         CRM_Core_DAO::freeResult();
     }
     // FIXME: there must be a better way
     foreach (array('main', 'other') as $moniker) {
         $contact =& ${$moniker};
         $preferred_communication_method = CRM_Utils_array::value('preferred_communication_method', $contact);
         $value = empty($preferred_communication_method) ? array() : $preferred_communication_method;
         $specialValues[$moniker] = array('preferred_communication_method' => $value, 'communication_style_id' => $value);
         if (!empty($contact['preferred_communication_method'])) {
             // api 3 returns pref_comm_method as an array, which breaks the lookup; so we reconstruct
             $prefCommList = is_array($specialValues[$moniker]['preferred_communication_method']) ? implode(CRM_Core_DAO::VALUE_SEPARATOR, $specialValues[$moniker]['preferred_communication_method']) : $specialValues[$moniker]['preferred_communication_method'];
             $specialValues[$moniker]['preferred_communication_method'] = CRM_Core_DAO::VALUE_SEPARATOR . $prefCommList . CRM_Core_DAO::VALUE_SEPARATOR;
         }
         $names = array('preferred_communication_method' => array('newName' => 'preferred_communication_method_display', 'groupName' => 'preferred_communication_method'));
         CRM_Core_OptionGroup::lookupValues($specialValues[$moniker], $names);
         if (!empty($contact['communication_style'])) {
             $specialValues[$moniker]['communication_style_id_display'] = $contact['communication_style'];
         }
     }
     static $optionValueFields = array();
     if (empty($optionValueFields)) {
         $optionValueFields = CRM_Core_OptionValue::getFields();
     }
     foreach ($optionValueFields as $field => $params) {
         $fields[$field]['title'] = $params['title'];
     }
     $diffs = self::findDifferences($main, $other);
     $rows = $elements = $relTableElements = $migrationInfo = array();
     $genders = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id');
     foreach ($diffs['contact'] as $field) {
         if ($field == 'contact_sub_type') {
             // CRM-15681 don't display sub-types in UI
             continue;
         }
         foreach (array('main', 'other') as $moniker) {
             $contact =& ${$moniker};
             $value = CRM_Utils_Array::value($field, $contact);
             if (isset($specialValues[$moniker][$field]) && is_string($specialValues[$moniker][$field])) {
                 $value = CRM_Core_DAO::VALUE_SEPARATOR . trim($specialValues[$moniker][$field], CRM_Core_DAO::VALUE_SEPARATOR) . CRM_Core_DAO::VALUE_SEPARATOR;
             }
             $label = isset($specialValues[$moniker]["{$field}_display"]) ? $specialValues[$moniker]["{$field}_display"] : $value;
             if (!empty($fields[$field]['type']) && $fields[$field]['type'] == CRM_Utils_Type::T_DATE) {
                 if ($value) {
                     $value = str_replace('-', '', $value);
                     $label = CRM_Utils_Date::customFormat($label);
                 } else {
                     $value = "null";
                 }
             } elseif (!empty($fields[$field]['type']) && $fields[$field]['type'] == CRM_Utils_Type::T_BOOLEAN) {
                 if ($label === '0') {
                     $label = ts('[ ]');
                 }
                 if ($label === '1') {
                     $label = ts('[x]');
                 }
             } elseif ($field == 'individual_prefix' || $field == 'prefix_id') {
                 $label = CRM_Utils_Array::value('individual_prefix', $contact);
                 $value = CRM_Utils_Array::value('prefix_id', $contact);
                 $field = 'prefix_id';
             } elseif ($field == 'individual_suffix' || $field == 'suffix_id') {
                 $label = CRM_Utils_Array::value('individual_suffix', $contact);
                 $value = CRM_Utils_Array::value('suffix_id', $contact);
                 $field = 'suffix_id';
             } elseif ($field == 'gender_id' && !empty($value)) {
                 $label = $genders[$value];
             } elseif ($field == 'current_employer_id' && !empty($value)) {
                 $label = "{$value} (" . CRM_Contact_BAO_Contact::displayName($value) . ")";
             }
             $rows["move_{$field}"][$moniker] = $label;
             if ($moniker == 'other') {
                 //CRM-14334
                 if ($value === NULL || $value == '') {
                     $value = 'null';
                 }
                 if ($value === 0 or $value === '0') {
                     $value = $qfZeroBug;
                 }
                 if (is_array($value) && empty($value[1])) {
                     $value[1] = NULL;
                 }
                 $elements[] = array('advcheckbox', "move_{$field}", NULL, NULL, NULL, $value);
                 $migrationInfo["move_{$field}"] = $value;
             }
         }
         $rows["move_{$field}"]['title'] = $fields[$field]['title'];
     }
     // handle location blocks.
     $locationBlocks = array('email', 'phone', 'address');
     $locations = array();
     foreach ($locationBlocks as $block) {
         foreach (array('main' => $mainId, 'other' => $otherId) as $moniker => $cid) {
             $cnt = 1;
             $values = civicrm_api($block, 'get', array('contact_id' => $cid, 'version' => 3));
             $count = $values['count'];
             if ($count) {
                 if ($count > $cnt) {
                     foreach ($values['values'] as $value) {
                         if ($block == 'address') {
                             CRM_Core_BAO_Address::fixAddress($value);
                             $display = CRM_Utils_Address::format($value);
                             $locations[$moniker][$block][$cnt] = $value;
                             $locations[$moniker][$block][$cnt]['display'] = $display;
                         } else {
                             $locations[$moniker][$block][$cnt] = $value;
                         }
                         $cnt++;
                     }
                 } else {
                     $id = $values['id'];
                     if ($block == 'address') {
                         CRM_Core_BAO_Address::fixAddress($values['values'][$id]);
                         $display = CRM_Utils_Address::format($values['values'][$id]);
                         $locations[$moniker][$block][$cnt] = $values['values'][$id];
                         $locations[$moniker][$block][$cnt]['display'] = $display;
                     } else {
                         $locations[$moniker][$block][$cnt] = $values['values'][$id];
                     }
                 }
             }
         }
     }
     $allLocationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     $mainLocBlock = $locBlockIds = array();
     $locBlockIds['main'] = $locBlockIds['other'] = array();
     foreach (array('Email', 'Phone', 'IM', 'OpenID', 'Address') as $block) {
         $name = strtolower($block);
         foreach (array('main', 'other') as $moniker) {
             $locIndex = CRM_Utils_Array::value($moniker, $locations);
             $blockValue = CRM_Utils_Array::value($name, $locIndex, array());
             if (empty($blockValue)) {
                 $locValue[$moniker][$name] = 0;
                 $locLabel[$moniker][$name] = $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] = CRM_Utils_Array::value($fldName, $blkValues);
                     $locTypes[$moniker][$name][$count] = $locTypeId;
                     if ($moniker == 'main' && in_array($name, $locationBlocks)) {
                         $mainLocBlock["main_{$name}{$locTypeId}"] = CRM_Utils_Array::value($fldName, $blkValues);
                         $locBlockIds['main'][$name][$locTypeId] = $blkValues['id'];
                     } else {
                         $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'] = CRM_Utils_Array::value($count, $locLabel['main'][$name]);
                 $rows["move_location_{$name}_{$count}"]['title'] = ts('%1:%2:%3', array(1 => $block, 2 => $count, 3 => $allLocationTypes[$locTypeId]));
                 $elements[] = array('advcheckbox', "move_location_{$name}_{$count}");
                 $migrationInfo["move_location_{$name}_{$count}"] = 1;
                 // 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 (in_array($name, $locationBlocks) && !empty($mainLocBlock)) {
                     $js = array('onChange' => "mergeBlock('{$name}', this, {$count} );");
                 }
                 $elements[] = array('select', "location[{$name}][{$count}][locTypeId]", NULL, $defaultLocType + $locTypeValues, $js);
                 // keep location-type-id same as that of other-contact
                 $migrationInfo['location'][$name][$count]['locTypeId'] = $locTypeId;
                 if ($name != 'address') {
                     $elements[] = array('advcheckbox', "location[{$name}][{$count}][operation]", NULL, ts('add new'));
                     // always use add operation
                     $migrationInfo['location'][$name][$count]['operation'] = 1;
                 }
             }
         }
     }
     // add the related tables and unset the ones that don't sport any of the duplicate contact's info
     $config = CRM_Core_Config::singleton();
     $mainUfId = CRM_Core_BAO_UFMatch::getUFId($mainId);
     $mainUser = NULL;
     if ($mainUfId) {
         // d6 compatible
         if ($config->userSystem->is_drupal == '1' && function_exists($mainUser)) {
             $mainUser = user_load($mainUfId);
         } elseif ($config->userFramework == 'Joomla') {
             $mainUser = JFactory::getUser($mainUfId);
         }
     }
     $otherUfId = CRM_Core_BAO_UFMatch::getUFId($otherId);
     $otherUser = NULL;
     if ($otherUfId) {
         // d6 compatible
         if ($config->userSystem->is_drupal == '1' && function_exists($mainUser)) {
             $otherUser = user_load($otherUfId);
         } elseif ($config->userFramework == 'Joomla') {
             $otherUser = JFactory::getUser($otherUfId);
         }
     }
     $relTables = CRM_Dedupe_Merger::relTables();
     $activeRelTables = CRM_Dedupe_Merger::getActiveRelTables($otherId);
     $activeMainRelTables = CRM_Dedupe_Merger::getActiveRelTables($mainId);
     foreach ($relTables as $name => $null) {
         if (!in_array($name, $activeRelTables) && !($name == 'rel_table_users' && in_array($name, $activeMainRelTables))) {
             unset($relTables[$name]);
             continue;
         }
         $relTableElements[] = array('checkbox', "move_{$name}");
         $migrationInfo["move_{$name}"] = 1;
         $relTables[$name]['main_url'] = str_replace('$cid', $mainId, $relTables[$name]['url']);
         $relTables[$name]['other_url'] = str_replace('$cid', $otherId, $relTables[$name]['url']);
         if ($name == 'rel_table_users') {
             $relTables[$name]['main_url'] = str_replace('%ufid', $mainUfId, $relTables[$name]['url']);
             $relTables[$name]['other_url'] = str_replace('%ufid', $otherUfId, $relTables[$name]['url']);
             $find = array('$ufid', '$ufname');
             if ($mainUser) {
                 $replace = array($mainUfId, $mainUser->name);
                 $relTables[$name]['main_title'] = str_replace($find, $replace, $relTables[$name]['title']);
             }
             if ($otherUser) {
                 $replace = array($otherUfId, $otherUser->name);
                 $relTables[$name]['other_title'] = str_replace($find, $replace, $relTables[$name]['title']);
             }
         }
         if ($name == 'rel_table_memberships') {
             $elements[] = array('checkbox', "operation[move_{$name}][add]", NULL, ts('add new'));
             $migrationInfo["operation"]["move_{$name}"]['add'] = 1;
         }
     }
     foreach ($relTables as $name => $null) {
         $relTables["move_{$name}"] = $relTables[$name];
         unset($relTables[$name]);
     }
     // handle custom fields
     $mainTree = CRM_Core_BAO_CustomGroup::getTree($main['contact_type'], CRM_Core_DAO::$_nullObject, $mainId, -1, CRM_Utils_Array::value('contact_sub_type', $main));
     $otherTree = CRM_Core_BAO_CustomGroup::getTree($main['contact_type'], CRM_Core_DAO::$_nullObject, $otherId, -1, CRM_Utils_Array::value('contact_sub_type', $other));
     CRM_Core_DAO::freeResult();
     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 (!empty($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, TRUE);
                     }
                 }
                 $value = "null";
                 if (!empty($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, TRUE);
                         if ($values['data'] === 0 || $values['data'] === '0') {
                             $values['data'] = $qfZeroBug;
                         }
                         $value = $values['data'] ? $values['data'] : $value;
                     }
                 }
                 $rows["move_custom_{$fid}"]['title'] = $field['label'];
                 $elements[] = array('advcheckbox', "move_custom_{$fid}", NULL, NULL, NULL, $value);
                 $migrationInfo["move_custom_{$fid}"] = $value;
             }
         }
     }
     $result = array('rows' => $rows, 'elements' => $elements, 'rel_table_elements' => $relTableElements, 'main_loc_block' => $mainLocBlock, 'rel_tables' => $relTables, 'main_details' => $main, 'other_details' => $other, 'migration_info' => $migrationInfo);
     $result['main_details']['loc_block_ids'] = $locBlockIds['main'];
     $result['other_details']['loc_block_ids'] = $locBlockIds['other'];
     return $result;
 }
Exemplo n.º 18
0
/**
 * get the uf_id given a contact_id
 *
 * @param int $contactID
 *
 * @return int ufID
 * @access public
 * @static
 */
function civicrm_uf_id_get($contactID)
{
    if ((int) $contactID > 0) {
        require_once 'CRM/Core/BAO/UFMatch.php';
        return CRM_Core_BAO_UFMatch::getUFId($contactID);
    } else {
        return civicrm_create_error('Param needs to be a positive integer.');
    }
}
Exemplo n.º 19
0
 /**
  * returns all the rows in the given offset and rowCount
  *
  * @param enum   $action   the action being performed
  * @param int    $offset   the row number to start from
  * @param int    $rowCount the number of rows to return
  * @param string $sort     the sql string that describes the sort order
  * @param enum   $output   what should the result set include (web/email/csv)
  *
  * @return int   the total number of rows for this action
  */
 function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
 {
     $multipleFields = array('url');
     //$sort object processing for location fields
     if ($sort) {
         $vars = $sort->_vars;
         $varArray = array();
         foreach ($vars as $key => $field) {
             $field = $vars[$key];
             $fieldArray = explode('-', $field['name']);
             $fieldType = CRM_Utils_Array::value('2', $fieldArray);
             if (is_numeric(CRM_Utils_Array::value('1', $fieldArray))) {
                 if (!in_array($fieldType, $multipleFields)) {
                     $locationType = new CRM_Core_DAO_LocationType();
                     $locationType->id = $fieldArray[1];
                     $locationType->find(TRUE);
                     if ($fieldArray[0] == 'email' || $fieldArray[0] == 'im' || $fieldArray[0] == 'phone') {
                         $field['name'] = "`" . $locationType->name . "-" . $fieldArray[0] . "-1`";
                     } else {
                         $field['name'] = "`" . $locationType->name . "-" . $fieldArray[0] . "`";
                     }
                 } else {
                     $field['name'] = "`website-" . $fieldArray[1] . "-{$fieldType}`";
                 }
             }
             $varArray[$key] = $field;
         }
         $sort->_vars = $varArray;
     }
     $additionalWhereClause = 'contact_a.is_deleted = 0';
     $returnQuery = NULL;
     if ($this->_multiRecordTableName) {
         $returnQuery = TRUE;
     }
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, NULL, NULL, NULL, NULL, $returnQuery, $additionalWhereClause);
     if ($returnQuery) {
         $resQuery = preg_replace('/GROUP BY contact_a.id[\\s]+ORDER BY/', ' ORDER BY', $result);
         $result = CRM_Core_DAO::executeQuery($resQuery);
     }
     // process the result of the query
     $rows = array();
     // check if edit is configured in profile settings
     if ($this->_gid) {
         $editLink = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'is_edit_link');
     }
     //FIXME : make sure to handle delete separately. CRM-4418
     $mask = CRM_Core_Action::mask(array(CRM_Core_Permission::getPermission()));
     if ($editLink && $mask & CRM_Core_Permission::EDIT) {
         // do not allow edit for anon users in joomla frontend, CRM-4668
         $config = CRM_Core_Config::singleton();
         if (!$config->userFrameworkFrontend) {
             $this->_editLink = TRUE;
         }
     }
     $links = self::links($this->_map, $this->_editLink, $this->_linkToUF, $this->_profileIds);
     $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     $names = array();
     static $skipFields = array('group', 'tag');
     foreach ($this->_fields as $key => $field) {
         // skip pseudo fields
         if (substr($key, 0, 9) == 'phone_ext') {
             continue;
         }
         if (!empty($field['in_selector']) && !in_array($key, $skipFields)) {
             if (strpos($key, '-') !== FALSE) {
                 $value = explode('-', $key);
                 $fieldName = CRM_Utils_Array::value(0, $value);
                 $id = CRM_Utils_Array::value(1, $value);
                 $type = CRM_Utils_Array::value(2, $value);
                 if (!in_array($fieldName, $multipleFields)) {
                     $locationTypeName = NULL;
                     if (is_numeric($id)) {
                         $locationTypeName = CRM_Utils_Array::value($id, $locationTypes);
                     } else {
                         if ($id == 'Primary') {
                             $locationTypeName = 1;
                         }
                     }
                     if (!$locationTypeName) {
                         continue;
                     }
                     $locationTypeName = str_replace(' ', '_', $locationTypeName);
                     if (in_array($fieldName, array('phone', 'im', 'email'))) {
                         if ($type) {
                             $names[] = "{$locationTypeName}-{$fieldName}-{$type}";
                         } else {
                             $names[] = "{$locationTypeName}-{$fieldName}";
                         }
                     } else {
                         $names[] = "{$locationTypeName}-{$fieldName}";
                     }
                 } else {
                     $names[] = "website-{$id}-{$fieldName}";
                 }
             } elseif ($field['name'] == 'id') {
                 $names[] = 'contact_id';
             } else {
                 $names[] = $field['name'];
             }
         }
     }
     $multipleSelectFields = array('preferred_communication_method' => 1);
     $multiRecordTableId = NULL;
     if ($this->_multiRecordTableName) {
         $multiRecordTableId = "{$this->_multiRecordTableName}_id";
     }
     // we need to determine of overlay profile should be shown
     $showProfileOverlay = CRM_Core_BAO_UFGroup::showOverlayProfile();
     while ($result->fetch()) {
         $this->_query->convertToPseudoNames($result);
         if (isset($result->country)) {
             // the query returns the untranslated country name
             $i18n = CRM_Core_I18n::singleton();
             $result->country = $i18n->translate($result->country);
         }
         $row = array();
         $empty = TRUE;
         $row[] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id, $showProfileOverlay);
         if ($result->sort_name) {
             $row[] = $result->sort_name;
             $empty = FALSE;
         } else {
             continue;
         }
         foreach ($names as $name) {
             if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 $row[] = CRM_Core_BAO_CustomField::getDisplayValue($result->{$name}, $cfID, $this->_options, $result->contact_id);
             } elseif (substr($name, -4) == '-url' && !empty($result->{$name})) {
                 $url = CRM_Utils_System::fixURL($result->{$name});
                 $typeId = substr($name, 0, -4) . "-website_type_id";
                 $typeName = CRM_Core_PseudoConstant::getLabel('CRM_Core_DAO_Website', 'website_type_id', $result->{$typeId});
                 if ($typeName) {
                     $row[] = "<a href=\"{$url}\">{$result->{$name}} ({$typeName})</a>";
                 } else {
                     $row[] = "<a href=\"{$url}\">{$result->{$name}}</a>";
                 }
             } elseif ($name == 'preferred_language') {
                 $row[] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'preferred_language', $result->{$name});
             } elseif ($multipleSelectFields && array_key_exists($name, $multipleSelectFields)) {
                 $paramsNew = array($name => $result->{$name});
                 $name = array($name => array('newName' => $name, 'groupName' => $name));
                 CRM_Core_OptionGroup::lookupValues($paramsNew, $name, FALSE);
                 $row[] = $paramsNew[$key];
             } elseif (strpos($name, '-im')) {
                 if (!empty($result->{$name})) {
                     $providerId = $name . "-provider_id";
                     $providerName = CRM_Core_PseudoConstant::getLabel('CRM_Core_DAO_IM', 'provider_id', $result->{$providerId});
                     $row[] = $result->{$name} . " ({$providerName})";
                 } else {
                     $row[] = '';
                 }
             } elseif (strpos($name, '-phone-')) {
                 $phoneExtField = str_replace('phone', 'phone_ext', $name);
                 if (isset($result->{$phoneExtField})) {
                     $row[] = $result->{$name} . " (" . $result->{$phoneExtField} . ")";
                 } else {
                     $row[] = $result->{$name};
                 }
             } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting'))) {
                 $dname = $name . '_display';
                 $row[] = $result->{$dname};
             } elseif (in_array($name, array('birth_date', 'deceased_date'))) {
                 $row[] = CRM_Utils_Date::customFormat($result->{$name});
             } elseif (isset($result->{$name})) {
                 $row[] = $result->{$name};
             } else {
                 $row[] = '';
             }
             if (!empty($result->{$name})) {
                 $empty = FALSE;
             }
         }
         $newLinks = $links;
         $params = array('id' => $result->contact_id, 'gid' => implode(',', $this->_profileIds));
         // pass record id param to view url for multi record view
         if ($multiRecordTableId && $newLinks) {
             if ($result->{$multiRecordTableId}) {
                 if ($newLinks[CRM_Core_Action::VIEW]['url'] == 'civicrm/profile/view') {
                     $newLinks[CRM_Core_Action::VIEW]['qs'] .= "&multiRecord=view&recordId=%%recordId%%&allFields=1";
                     $params['recordId'] = $result->{$multiRecordTableId};
                 }
             }
         }
         if ($this->_linkToUF) {
             $ufID = CRM_Core_BAO_UFMatch::getUFId($result->contact_id);
             if (!$ufID) {
                 unset($newLinks[CRM_Core_Action::PROFILE]);
             } else {
                 $params['ufID'] = $ufID;
             }
         }
         $row[] = CRM_Core_Action::formLink($newLinks, $mask, $params, ts('more'), FALSE, 'profile.selector.row', 'Contact', $result->contact_id);
         if (!$empty) {
             $rows[] = $row;
         }
     }
     return $rows;
 }
Exemplo n.º 20
0
 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('merge duplicate contacts')) {
         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);
     self::validateContacts($cid, $oid);
     // Block access if user does not have EDIT permissions for both contacts.
     require_once 'CRM/Contact/BAO/Contact/Permission.php';
     if (!(CRM_Contact_BAO_Contact_Permission::allow($cid, CRM_Core_Permission::EDIT) && CRM_Contact_BAO_Contact_Permission::allow($oid, CRM_Core_Permission::EDIT))) {
         CRM_Utils_System::permissionDenied();
     }
     // get user info of main contact.
     $config = CRM_Core_Config::singleton();
     require_once 'CRM/Core/Permission.php';
     $viewUser = CRM_Core_Permission::check('access user profiles');
     $mainUfId = CRM_Core_BAO_UFMatch::getUFId($cid);
     if ($mainUfId) {
         if ($config->userFramework == 'Drupal') {
             $mainUser = user_load($mainUfId);
         } else {
             if ($config->userFramework == 'Joomla') {
                 $mainUser = JFactory::getUser($mainUfId);
             }
         }
     }
     $this->assign('mainUfId', $mainUfId);
     $this->assign('mainUfName', $mainUser->name);
     // get user info of other contact.
     $otherUfId = CRM_Core_BAO_UFMatch::getUFId($oid);
     if ($otherUfId) {
         if ($config->userFramework == 'Drupal') {
             $otherUser = user_load($otherUfId);
         } else {
             if ($config->userFramework == 'Joomla') {
                 $otherUser = JFactory::getUser($otherUfId);
             }
         }
     }
     $this->assign('otherUfId', $otherUfId);
     $this->assign('otherUfName', $otherUser->name);
     $cmsUser = $mainUfId && $otherUfId ? true : false;
     $this->assign('user', $cmsUser);
     $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/contact/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, 'return.contact_sub_type' => 1);
     $otherParams = array('contact_id' => $oid, 'return.display_name' => 1, 'return.contact_sub_type' => 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'));
     }
     require_once 'CRM/Contact/BAO/ContactType.php';
     $subtypes = CRM_Contact_BAO_ContactType::subTypePairs(null, true, '');
     $this->assign('contact_type', $main['contact_type']);
     $this->assign('main_contact_subtype', $subtypes[$main['contact_sub_type']]);
     $this->assign('other_contact_subtype', $subtypes[$other['contact_sub_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, true);
                     }
                 }
                 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, true);
                         $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);
     $activeMainRelTables = CRM_Dedupe_Merger::getActiveRelTables($cid);
     foreach ($relTables as $name => $null) {
         if (!in_array($name, $activeRelTables) && !($name == 'rel_table_users' && in_array($name, $activeMainRelTables))) {
             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']);
         if ($name == 'rel_table_users') {
             $relTables[$name]['main_url'] = str_replace('$ufid', $mainUfId, $relTables[$name]['url']);
             $relTables[$name]['other_url'] = str_replace('$ufid', $otherUfId, $relTables[$name]['url']);
             $find = array('$ufid', '$ufname');
             $replace = array($mainUfId, $mainUser->name);
             $relTables[$name]['main_title'] = str_replace($find, $replace, $relTables[$name]['title']);
             $replace = array($otherUfId, $otherUser->name);
             $relTables[$name]['other_title'] = str_replace($find, $replace, $relTables[$name]['title']);
         }
         if ($name == 'rel_table_memberships') {
             $this->addElement('checkbox', "operation[move_{$name}][add]", null, ts('add new'));
         }
     }
     foreach ($relTables as $name => $null) {
         $relTables["move_{$name}"] = $relTables[$name];
         unset($relTables[$name]);
     }
     $this->assign('rel_tables', $relTables);
     $this->assign('userContextURL', $session->readUserContext());
 }
    if ($contact['values'][$row->civicrm_address_contact_id]['api.Phone.get']['count'] != 0) {
        foreach ($contact['values'][$row->civicrm_address_contact_id]['api.Phone.get']['values'] as $phones) {
            $phoneDiv .= "<a href='tel:" . $phones['phone'] . "'>" . $phones['phone'] . "</a><br/>";
        }
    }
    $tempArray = $areas = array();
    // Display Name
    if (!empty($contact['values'][$row->civicrm_address_contact_id]['api.CustomValue.get']['values']) && !empty($contact['values'][$row->civicrm_address_contact_id]['api.CustomValue.get']['values'][8]['latest'])) {
        $disName = $contact['values'][$row->civicrm_address_contact_id]['api.CustomValue.get']['values'][8]['latest'];
        $disName = "<a href='" . $contactLink . "'>" . $disName . "</a>";
    }
    if ($disName == '') {
        $disName = $displayName;
    }
    // Drupal Image
    $uid = CRM_Core_BAO_UFMatch::getUFId($row->civicrm_address_contact_id);
    if (!empty($uid)) {
        $user = user_load($uid);
    }
    $state = $row->civicrm_address_city;
    if (isset($row->civicrm_address_state_province_id)) {
        $state .= ', ' . CRM_Core_PseudoConstant::stateProvinceAbbreviation($row->civicrm_address_state_province_id);
    }
    // Distance
    if (isset($row->field_data_field_geo_code_1_field_geofield_distance)) {
        $distance = round($row->field_data_field_geo_code_1_field_geofield_distance, 1) . ' miles away';
    }
}
if ($memberships['membership_type_id'] == 5) {
    $cert_output = "<div class='views-field-views-conditional-1'><div class='mcfm_certified'><a href='/mediation/mcfm-certified-mediators' target='_blank'>\n    <img src='/sites/default/files/icons/mcfm-certified-member_38h.png' title='MCFM Certified Mediators have additional mediation experience. Click to learn more.'></a></div></div>";
} else {
Exemplo n.º 22
0
 /**
  * Add urls for display in the actions menu
  */
 static function addUrls(&$obj, $cid)
 {
     // TODO rewrite without so many hard-coded CMS bits; use abstractions like CRM_Core_Permission::check('cms:...') and CRM_Utils_System
     $config = CRM_Core_Config::singleton();
     $session = CRM_Core_Session::singleton();
     $uid = CRM_Core_BAO_UFMatch::getUFId($cid);
     $userRecordUrl = NULL;
     if ($uid) {
         if ($config->userSystem->is_drupal == '1' && ($session->get('userID') == $cid || CRM_Core_Permission::checkAnyPerm(array('cms:administer users', 'cms:view user account')))) {
             $userRecordUrl = CRM_Utils_System::url('user/' . $uid);
         } elseif ($config->userFramework == 'Joomla') {
             $userRecordUrl = NULL;
             // if logged in user is super user, then he can view other users joomla profile
             if (JFactory::getUser()->authorise('core.admin')) {
                 $userRecordUrl = $config->userFrameworkBaseURL . "index.php?option=com_users&view=user&task=user.edit&id=" . $uid;
             } elseif ($session->get('userID') == $cid) {
                 $userRecordUrl = $config->userFrameworkBaseURL . "index.php?option=com_admin&view=profile&layout=edit&id=" . $uid;
             }
         } elseif ($config->userFramework == 'WordPress' && ($session->get('userID') == $cid || CRM_Core_Permission::checkAnyPerm(array('cms:administer users')))) {
             $userRecordUrl = $config->userFrameworkBaseURL . "wp-admin/user-edit.php?user_id=" . $uid;
         }
         $obj->assign('userRecordUrl', $userRecordUrl);
         $obj->assign('userRecordId', $uid);
     } elseif ($config->userSystem->is_drupal == '1' && CRM_Core_Permission::check('administer users') || $config->userFramework == 'Joomla' && JFactory::getUser()->authorise('core.create', 'com_users')) {
         $userAddUrl = CRM_Utils_System::url('civicrm/contact/view/useradd', 'reset=1&action=add&cid=' . $cid);
         $obj->assign('userAddUrl', $userAddUrl);
     }
     if (CRM_Core_Permission::check('access Contact Dashboard')) {
         $dashboardURL = CRM_Utils_System::url('civicrm/user', "reset=1&id={$cid}");
         $obj->assign('dashboardURL', $dashboardURL);
     }
     // See if other modules want to add links to the activtity bar
     $hookLinks = array();
     CRM_Utils_Hook::links('view.contact.activity', 'Contact', $cid, $hookLinks, CRM_Core_DAO::$_nullObject, CRM_Core_DAO::$_nullObject);
     if (is_array($hookLinks)) {
         $obj->assign('hookLinks', $hookLinks);
     }
 }
Exemplo n.º 23
0
 /**
  * @inheritDoc
  */
 public function getUserRecordUrl($contactID)
 {
     $uid = CRM_Core_BAO_UFMatch::getUFId($contactID);
     if (CRM_Core_Session::singleton()->get('userID') == $contactID || CRM_Core_Permission::checkAnyPerm(array('cms:administer users'))) {
         return CRM_Core_Config::singleton()->userFrameworkBaseURL . "wp-admin/user-edit.php?user_id=" . $uid;
     }
 }
Exemplo n.º 24
0
/**  
 * get the uf_id given a contact_id  
 *  
 * @param int $contactID
 *  
 * @return int ufID
 * @access public     
 * @static  
 */
function crm_uf_get_uf_id($contactID)
{
    require_once 'CRM/Core/BAO/UFMatch.php';
    return CRM_Core_BAO_UFMatch::getUFId($contactID);
}
Exemplo n.º 25
0
 /**
  * Add urls for display in the actions menu.
  * @param CRM_Core_Page $obj
  * @param int $cid
  */
 public static function addUrls(&$obj, $cid)
 {
     $uid = CRM_Core_BAO_UFMatch::getUFId($cid);
     if ($uid) {
         $userRecordUrl = CRM_Core_Config::singleton()->userSystem->getUserRecordUrl($cid);
         $obj->assign('userRecordUrl', $userRecordUrl);
         $obj->assign('userRecordId', $uid);
     } elseif (CRM_Core_Config::singleton()->userSystem->checkPermissionAddUser()) {
         $userAddUrl = CRM_Utils_System::url('civicrm/contact/view/useradd', 'reset=1&action=add&cid=' . $cid);
         $obj->assign('userAddUrl', $userAddUrl);
     }
     if (CRM_Core_Permission::check('access Contact Dashboard')) {
         $dashboardURL = CRM_Utils_System::url('civicrm/user', "reset=1&id={$cid}");
         $obj->assign('dashboardURL', $dashboardURL);
     }
     // See if other modules want to add links to the activtity bar
     $hookLinks = array();
     CRM_Utils_Hook::links('view.contact.activity', 'Contact', $cid, $hookLinks, CRM_Core_DAO::$_nullObject, CRM_Core_DAO::$_nullObject);
     if (is_array($hookLinks)) {
         $obj->assign('hookLinks', $hookLinks);
     }
 }
Exemplo n.º 26
0
 function loadCMSBootstrap()
 {
     $q = CRM_Utils_array::value('q', $_REQUEST);
     $args = explode('/', $q);
     // If the function isn't in the civicrm namespace or request
     // is for login or ping
     if (empty($args) || $args[0] != 'civicrm' || count($args) != 3 && $args[1] != 'login' && $args[1] != 'ping' || $args[1] == 'login' || $args[1] == 'ping') {
         return;
     }
     $uid = null;
     $session = CRM_Core_Session::singleton();
     if (!CRM_Utils_System::authenticateKey(false)) {
         return;
     }
     if ($session->get('PHPSESSID') && $session->get('cms_user_id')) {
         $uid = $session->get('cms_user_id');
     }
     if (!$uid) {
         require_once 'CRM/Core/DAO.php';
         require_once 'CRM/Utils/Request.php';
         $store = null;
         $api_key = CRM_Utils_Request::retrieve('api_key', 'String', $store, false, null, 'REQUEST');
         $contact_id = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $api_key, 'id', 'api_key');
         if ($contact_id) {
             require_once 'CRM/Core/BAO/UFMatch.php';
             $uid = CRM_Core_BAO_UFMatch::getUFId($contact_id);
         }
     }
     if ($uid) {
         CRM_Utils_System::loadBootStrap(null, null, $uid);
     }
 }