示例#1
0
 function testGet()
 {
     $location = $this->locationAdd($this->_contactID);
     $proper = array('country_id' => 1228, 'county_id' => 3, 'state_province_id' => 1021, 'supplemental_address_1' => 'Hallmark Ct', 'supplemental_address_2' => 'Jersey Village');
     $result = civicrm_location_get(array('contact_id' => $this->_contactId));
     foreach ($result as $location) {
         if (CRM_Utils_Array::value('address', $location)) {
             foreach ($proper as $field => $value) {
                 $this->assertEquals($location['address'][$field], $value);
             }
         }
     }
 }
示例#2
0
/**
 *  Update a specified location with the provided property values.
 * 
 *  @param  object  $contact        A valid Contact object (passed by reference).
 *  @param  string  $location_id    Valid (db-level) id for location to be updated. 
 *  @param  Array   $params         Associative array of property name/value pairs to be updated
 *
 *  @return Location object with updated property values
 * 
 *  @access public
 *
 */
function civicrm_location_update($params)
{
    _civicrm_initialize();
    if (!is_array($params)) {
        return civicrm_create_error('Params need to be of type array!');
    }
    if (!isset($params['contact_id'])) {
        return civicrm_create_error(ts('$contact is not valid contact datatype'));
    }
    $unsetVersion = false;
    $locationTypes = array();
    $allLocationTypes = CRM_Core_PseudoConstant::locationType(true);
    if ('3.0' != CRM_Utils_Array::value('version', $params)) {
        //force to use 3.0 version for get location api's.
        $params['version'] = '3.0';
        $unsetVersion = true;
        if (!($locationTypeId = CRM_Utils_Array::value('location_type_id', $params)) && !CRM_Utils_Rule::integer($locationTypeId)) {
            return civicrm_create_error(ts('missing or invalid location_type_id'));
        }
        $locationTypes = CRM_Utils_Array::value('location_type', $params);
        //if location_type array absent and location_type_id pass build array.
        if ((!is_array($locationTypes) || !count($locationTypes)) && $locationTypeId) {
            require_once 'CRM/Core/PseudoConstant.php';
            if ($locName = CRM_Utils_Array::value($locationTypeId, $allLocationTypes)) {
                $locationTypes = array($locName);
            }
        }
    } else {
        $locTypeIds = array();
        foreach (array('email', 'phone', 'im', 'address', 'openid') as $name) {
            if (isset($params[$name]) && is_array($params[$name])) {
                foreach ($params[$name] as $count => $values) {
                    if (($name = CRM_Utils_Array::value('location_type', $values)) && !in_array($name, $locationTypes)) {
                        $locationTypes[] = $name;
                    }
                    if (($id = CRM_Utils_Array::value('location_type_id', $values)) && !in_array($id, $locTypeIds)) {
                        $locTypeIds[] = $id;
                    }
                }
            }
        }
        //get all location types.
        foreach ($locTypeIds as $locId) {
            if (($name = CRM_Utils_Array::value($locId, $allLocationTypes)) && !in_array($name, $locationTypes)) {
                $locationTypes[] = $name;
            }
        }
    }
    if (!empty($locationTypes)) {
        $params['location_type'] = $locationTypes;
    }
    //get location filter by loc type.
    $locations =& civicrm_location_get($params);
    if ($unsetVersion) {
        unset($params['version']);
    }
    if (CRM_Utils_System::isNull($locations)) {
        return civicrm_create_error(ts("Invalid Location Type(s) : %1", array(1 => implode(', ', CRM_Utils_Array::value('location_type', $params)))));
    }
    $location =& _civicrm_location_update($params, $locations);
    return $location;
}
示例#3
0
文件: Merge.php 项目: ksecor/civicrm
 function preProcess()
 {
     require_once 'api/v2/Contact.php';
     require_once 'CRM/Core/BAO/CustomGroup.php';
     require_once 'CRM/Core/OptionGroup.php';
     require_once 'CRM/Core/OptionValue.php';
     if (!CRM_Core_Permission::check('administer CiviCRM')) {
         CRM_Core_Error::fatal(ts('You do not have access to this page'));
     }
     $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, true);
     $oid = CRM_Utils_Request::retrieve('oid', 'Positive', $this, true);
     $rgid = CRM_Utils_Request::retrieve('rgid', 'Positive', $this, false);
     $gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, false);
     $session =& CRM_Core_Session::singleton();
     // context fixed.
     if ($rgid) {
         $urlParam = "reset=1&action=browse&rgid={$rgid}";
         if ($gid) {
             $urlParam .= "&gid={$gid}";
         }
         $session->pushUserContext(CRM_Utils_system::url('civicrm/admin/dedupefind', $urlParam));
     }
     // ensure that oid is not the current user, if so refuse to do the merge
     if ($session->get('userID') == $oid) {
         $display_name = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $oid, 'display_name');
         $message = ts('The contact record which is linked to the currently logged in user account - \'%1\' - cannot be deleted.', array(1 => $display_name));
         CRM_Core_Error::statusBounce($message);
     }
     $diffs = CRM_Dedupe_Merger::findDifferences($cid, $oid);
     $mainParams = array('contact_id' => $cid, 'return.display_name' => 1);
     $otherParams = array('contact_id' => $oid, 'return.display_name' => 1);
     // API 2 has to have the requested fields spelt-out for it
     foreach (CRM_Dedupe_Merger::$validFields as $field) {
         $mainParams["return.{$field}"] = $otherParams["return.{$field}"] = 1;
     }
     $main =& civicrm_contact_get($mainParams);
     //CRM-4524
     $main = reset($main);
     if ($main['contact_id'] != $cid) {
         CRM_Core_Error::fatal(ts('The main contact record does not exist'));
     }
     $other =& civicrm_contact_get($otherParams);
     //CRM-4524
     $other = reset($other);
     if ($other['contact_id'] != $oid) {
         CRM_Core_Error::fatal(ts('The other contact record does not exist'));
     }
     $this->assign('contact_type', $main['contact_type']);
     $this->assign('main_name', $main['display_name']);
     $this->assign('other_name', $other['display_name']);
     $this->assign('main_cid', $main['contact_id']);
     $this->assign('other_cid', $other['contact_id']);
     $this->_cid = $cid;
     $this->_oid = $oid;
     $this->_rgid = $rgid;
     $this->_contactType = $main['contact_type'];
     $this->addElement('checkbox', 'toggleSelect', null, null, array('onclick' => "return toggleCheckboxVals('move_',this);"));
     require_once "CRM/Contact/DAO/Contact.php";
     $fields =& CRM_Contact_DAO_Contact::fields();
     // FIXME: there must be a better way
     foreach (array('main', 'other') as $moniker) {
         $contact =& ${$moniker};
         $specialValues[$moniker] = array('preferred_communication_method' => $contact['preferred_communication_method']);
         $names = array('preferred_communication_method' => array('newName' => 'preferred_communication_method_display', 'groupName' => 'preferred_communication_method'));
         CRM_Core_OptionGroup::lookupValues($specialValues[$moniker], $names);
     }
     foreach (CRM_Core_OptionValue::getFields() as $field => $params) {
         $fields[$field]['title'] = $params['title'];
     }
     if (!isset($diffs['contact'])) {
         $diffs['contact'] = array();
     }
     foreach ($diffs['contact'] as $field) {
         foreach (array('main', 'other') as $moniker) {
             $contact =& ${$moniker};
             $value = CRM_Utils_Array::value($field, $contact);
             $label = isset($specialValues[$moniker][$field]) ? $specialValues[$moniker]["{$field}_display"] : $value;
             if ($fields[$field]['type'] == CRM_Utils_Type::T_DATE) {
                 if ($value) {
                     $value = str_replace('-', '', $value);
                     $label = CRM_Utils_Date::customFormat($label);
                 } else {
                     $value = "null";
                 }
             } elseif ($fields[$field]['type'] == CRM_Utils_Type::T_BOOLEAN) {
                 if ($label === '0') {
                     $label = ts('[ ]');
                 }
                 if ($label === '1') {
                     $label = ts('[x]');
                 }
             }
             $rows["move_{$field}"][$moniker] = $label;
             if ($moniker == 'other') {
                 if ($value === null) {
                     $value = 'null';
                 }
                 if ($value === 0 or $value === '0') {
                     $value = $this->_qfZeroBug;
                 }
                 $this->addElement('advcheckbox', "move_{$field}", null, null, null, $value);
             }
         }
         $rows["move_{$field}"]['title'] = $fields[$field]['title'];
     }
     // handle location blocks.
     require_once 'api/v2/Location.php';
     $mainParams['version'] = $otherParams['version'] = '3.0';
     $locations['main'] =& civicrm_location_get($mainParams);
     $locations['other'] =& civicrm_location_get($otherParams);
     $allLocationTypes = CRM_Core_PseudoConstant::locationType();
     $mainLocAddress = array();
     foreach (array('Email', 'Phone', 'IM', 'OpenID', 'Address') as $block) {
         $name = strtolower($block);
         foreach (array('main', 'other') as $moniker) {
             $blockValue = CRM_Utils_Array::value($name, $locations[$moniker], array());
             if (empty($blockValue)) {
                 $locValue[$moniker][$name] = 0;
                 $locLabel[$moniker][$name] = array();
                 $locTypes[$moniker][$name] = array();
             } else {
                 $locValue[$moniker][$name] = true;
                 foreach ($blockValue as $count => $blkValues) {
                     $fldName = $name;
                     $locTypeId = $blkValues['location_type_id'];
                     if ($name == 'im') {
                         $fldName = 'name';
                     }
                     if ($name == 'address') {
                         $fldName = 'display';
                     }
                     $locLabel[$moniker][$name][$count] = $blkValues[$fldName];
                     $locTypes[$moniker][$name][$count] = $locTypeId;
                     if ($moniker == 'main' && $name == 'address') {
                         $mainLocAddress["main_{$locTypeId}"] = $blkValues[$fldName];
                         $this->_locBlockIds['main']['address'][$locTypeId] = $blkValues['id'];
                     } else {
                         $this->_locBlockIds[$moniker][$name][$count] = $blkValues['id'];
                     }
                 }
             }
         }
         if ($locValue['other'][$name] != 0) {
             foreach ($locLabel['other'][$name] as $count => $value) {
                 $locTypeId = $locTypes['other'][$name][$count];
                 $rows["move_location_{$name}_{$count}"]['other'] = $value;
                 $rows["move_location_{$name}_{$count}"]['main'] = $locLabel['main'][$name][$count];
                 $rows["move_location_{$name}_{$count}"]['title'] = ts('%1:%2:%3', array(1 => $block, 2 => $count, 3 => $allLocationTypes[$locTypeId]));
                 $this->addElement('advcheckbox', "move_location_{$name}_{$count}");
                 // make sure default location type is always on top
                 $mainLocTypeId = CRM_Utils_Array::value($count, $locTypes['main'][$name], $locTypeId);
                 $locTypeValues = $allLocationTypes;
                 $defaultLocType = array($mainLocTypeId => $locTypeValues[$mainLocTypeId]);
                 unset($locTypeValues[$mainLocTypeId]);
                 // keep 1-1 mapping for address - location type.
                 $js = null;
                 if ($name == 'address' && !empty($mainLocAddress)) {
                     $js = array('onChange' => "mergeAddress( this, {$count} );");
                 }
                 $this->addElement('select', "location[{$name}][{$count}][locTypeId]", null, $defaultLocType + $locTypeValues, $js);
                 if ($name != 'address') {
                     $this->addElement('advcheckbox', "location[{$name}][{$count}][operation]", null, ts('add new'));
                 }
             }
         }
     }
     $this->assign('mainLocAddress', json_encode($mainLocAddress));
     // handle custom fields
     $mainTree =& CRM_Core_BAO_CustomGroup::getTree($this->_contactType, $this, $this->_cid, -1);
     $otherTree =& CRM_Core_BAO_CustomGroup::getTree($this->_contactType, $this, $this->_oid, -1);
     if (!isset($diffs['custom'])) {
         $diffs['custom'] = array();
     }
     foreach ($otherTree as $gid => $group) {
         $foundField = false;
         if (!isset($group['fields'])) {
             continue;
         }
         foreach ($group['fields'] as $fid => $field) {
             if (in_array($fid, $diffs['custom'])) {
                 if (!$foundField) {
                     $rows["custom_group_{$gid}"]['title'] = $group['title'];
                     $foundField = true;
                 }
                 if (is_array($mainTree[$gid]['fields'][$fid]['customValue'])) {
                     foreach ($mainTree[$gid]['fields'][$fid]['customValue'] as $valueId => $values) {
                         $rows["move_custom_{$fid}"]['main'] = CRM_Core_BAO_CustomGroup::formatCustomValues($values, $field);
                     }
                 }
                 if (is_array($otherTree[$gid]['fields'][$fid]['customValue'])) {
                     foreach ($otherTree[$gid]['fields'][$fid]['customValue'] as $valueId => $values) {
                         $rows["move_custom_{$fid}"]['other'] = CRM_Core_BAO_CustomGroup::formatCustomValues($values, $field);
                         $value = $values['data'] ? $values['data'] : $this->_qfZeroBug;
                     }
                 }
                 $rows["move_custom_{$fid}"]['title'] = $field['label'];
                 $this->addElement('advcheckbox', "move_custom_{$fid}", null, null, null, $value);
             }
         }
     }
     $this->assign('rows', $rows);
     // add the related tables and unset the ones that don't sport any of the duplicate contact's info
     $relTables = CRM_Dedupe_Merger::relTables();
     $activeRelTables = CRM_Dedupe_Merger::getActiveRelTables($oid);
     foreach ($relTables as $name => $null) {
         if (!in_array($name, $activeRelTables)) {
             unset($relTables[$name]);
             continue;
         }
         $this->addElement('checkbox', "move_{$name}");
         $relTables[$name]['main_url'] = str_replace('$cid', $cid, $relTables[$name]['url']);
         $relTables[$name]['other_url'] = str_replace('$cid', $oid, $relTables[$name]['url']);
     }
     foreach ($relTables as $name => $null) {
         $relTables["move_{$name}"] = $relTables[$name];
         unset($relTables[$name]);
     }
     $this->assign('rel_tables', $relTables);
 }