/**
  * process the form
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $params = $this->exportValues();
     // need to process / save address
     $params['contact_id'] = $this->_contactId;
     $params['updateBlankLocInfo'] = TRUE;
     // process shared contact address.
     CRM_Contact_BAO_Contact_Utils::processSharedAddress($params['address']);
     if ($this->_parseStreetAddress) {
         CRM_Contact_Form_Contact::parseAddress($params);
     }
     if ($this->_addressId > 0) {
         $params['address'][$this->_locBlockNo]['id'] = $this->_addressId;
     }
     // save address changes
     $address = CRM_Core_BAO_Address::create($params, TRUE);
     // make entry in log table
     CRM_Core_BAO_Log::register($this->_contactId, 'civicrm_contact', $this->_contactId);
     $response = array('status' => 'save', 'addressId' => $address[0]->id);
     $this->postProcessHook();
     echo json_encode($response);
     CRM_Utils_System::civiExit();
 }
示例#2
0
文件: Inline.php 项目: kidaa30/yes
 /**
  * Add entry to log table.
  *
  * @return void
  */
 protected function log()
 {
     CRM_Core_BAO_Log::register($this->_contactId, 'civicrm_contact', $this->_contactId);
 }
示例#3
0
 /**
  * Takes an associative array and creates a note object.
  *
  * the function extract all the params it needs to initialize the create a
  * note object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array $params
  *   (reference) an assoc array of name/value pairs.
  * @param array $ids
  *   (deprecated) associated array with note id - preferably set $params['id'].
  *
  * @return object
  *   $note CRM_Core_BAO_Note object
  */
 public static function add(&$params, $ids = array())
 {
     $dataExists = self::dataExists($params);
     if (!$dataExists) {
         return CRM_Core_DAO::$_nullObject;
     }
     $note = new CRM_Core_BAO_Note();
     if (!isset($params['modified_date'])) {
         $params['modified_date'] = date("Ymd");
     }
     if (!isset($params['privacy'])) {
         $params['privacy'] = 0;
     }
     $note->copyValues($params);
     if (empty($params['contact_id'])) {
         if ($params['entity_table'] == 'civicrm_contact') {
             $note->contact_id = $params['entity_id'];
         }
     }
     $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('id', $ids));
     if ($id) {
         $note->id = $id;
     }
     $note->save();
     // check and attach and files as needed
     CRM_Core_BAO_File::processAttachment($params, 'civicrm_note', $note->id);
     if ($note->entity_table == 'civicrm_contact') {
         CRM_Core_BAO_Log::register($note->entity_id, 'civicrm_note', $note->id);
         $displayName = CRM_Contact_BAO_Contact::displayName($note->entity_id);
         $noteActions = FALSE;
         $session = CRM_Core_Session::singleton();
         if ($session->get('userID')) {
             if ($session->get('userID') == $note->entity_id) {
                 $noteActions = TRUE;
             } elseif (CRM_Contact_BAO_Contact_Permission::allow($note->entity_id, CRM_Core_Permission::EDIT)) {
                 $noteActions = TRUE;
             }
         }
         $recentOther = array();
         if ($noteActions) {
             $recentOther = array('editUrl' => CRM_Utils_System::url('civicrm/contact/view/note', "reset=1&action=update&cid={$note->entity_id}&id={$note->id}&context=home"), 'deleteUrl' => CRM_Utils_System::url('civicrm/contact/view/note', "reset=1&action=delete&cid={$note->entity_id}&id={$note->id}&context=home"));
         }
         // add the recently created Note
         CRM_Utils_Recent::add($displayName . ' - ' . $note->subject, CRM_Utils_System::url('civicrm/contact/view/note', "reset=1&action=view&cid={$note->entity_id}&id={$note->id}&context=home"), $note->id, 'Note', $note->entity_id, $displayName, $recentOther);
     }
     return $note;
 }
 /**
  * Takes an associative array and creates a contact object.
  *
  * The function extracts all the params it needs to initialize the create a
  * contact object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array $params
  *   (reference) an assoc array of name/value pairs.
  *
  * @return CRM_Contact_BAO_Contact|CRM_Core_Error|NULL
  *   Created or updated contact object or error object.
  *   (error objects are being phased out in favour of exceptions)
  */
 public static function add(&$params)
 {
     $contact = new CRM_Contact_DAO_Contact();
     if (empty($params)) {
         return NULL;
     }
     // Fix for validate contact sub type CRM-5143.
     if (isset($params['contact_sub_type'])) {
         if (empty($params['contact_sub_type'])) {
             $params['contact_sub_type'] = 'null';
         } else {
             if (!CRM_Contact_BAO_ContactType::isExtendsContactType($params['contact_sub_type'], $params['contact_type'], TRUE)) {
                 // we'll need to fix tests to handle this
                 // CRM-7925
                 CRM_Core_Error::fatal(ts('The Contact Sub Type does not match the Contact type for this record'));
             }
             if (is_array($params['contact_sub_type'])) {
                 $params['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $params['contact_sub_type']) . CRM_Core_DAO::VALUE_SEPARATOR;
             } else {
                 $params['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . trim($params['contact_sub_type'], CRM_Core_DAO::VALUE_SEPARATOR) . CRM_Core_DAO::VALUE_SEPARATOR;
             }
         }
     } else {
         // Reset the value.
         // CRM-101XX.
         $params['contact_sub_type'] = 'null';
     }
     // Fixed contact source.
     if (isset($params['contact_source'])) {
         $params['source'] = $params['contact_source'];
     }
     // Fix for preferred communication method.
     $prefComm = CRM_Utils_Array::value('preferred_communication_method', $params);
     if ($prefComm && is_array($prefComm)) {
         unset($params['preferred_communication_method']);
         $newPref = array();
         foreach ($prefComm as $k => $v) {
             if ($v) {
                 $newPref[$k] = $v;
             }
         }
         $prefComm = $newPref;
         if (is_array($prefComm) && !empty($prefComm)) {
             $prefComm = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($prefComm)) . CRM_Core_DAO::VALUE_SEPARATOR;
             $contact->preferred_communication_method = $prefComm;
         } else {
             $contact->preferred_communication_method = '';
         }
     }
     $allNull = $contact->copyValues($params);
     $contact->id = CRM_Utils_Array::value('contact_id', $params);
     if ($contact->contact_type == 'Individual') {
         $allNull = FALSE;
         // Format individual fields.
         CRM_Contact_BAO_Individual::format($params, $contact);
     } elseif ($contact->contact_type == 'Household') {
         if (isset($params['household_name'])) {
             $allNull = FALSE;
             $contact->display_name = $contact->sort_name = CRM_Utils_Array::value('household_name', $params, '');
         }
     } elseif ($contact->contact_type == 'Organization') {
         if (isset($params['organization_name'])) {
             $allNull = FALSE;
             $contact->display_name = $contact->sort_name = CRM_Utils_Array::value('organization_name', $params, '');
         }
     }
     $privacy = CRM_Utils_Array::value('privacy', $params);
     if ($privacy && is_array($privacy) && !empty($privacy)) {
         $allNull = FALSE;
         foreach (self::$_commPrefs as $name) {
             $contact->{$name} = CRM_Utils_Array::value($name, $privacy, FALSE);
         }
     }
     // Since hash was required, make sure we have a 0 value for it (CRM-1063).
     // @todo - does this mean we can remove this block?
     // Fixed in 1.5 by making hash optional, only do this in create mode, not update.
     if ((!array_key_exists('hash', $contact) || !$contact->hash) && !$contact->id) {
         $allNull = FALSE;
         $contact->hash = md5(uniqid(rand(), TRUE));
     }
     // Even if we don't need $employerId, it's important to call getFieldValue() before
     // the contact is saved because we want the existing value to be cached.
     // createCurrentEmployerRelationship() needs the old value not the updated one. CRM-10788
     $employerId = empty($contact->id) ? NULL : CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contact->id, 'employer_id');
     if (!$allNull) {
         $contact->save();
         CRM_Core_BAO_Log::register($contact->id, 'civicrm_contact', $contact->id);
     }
     if ($contact->contact_type == 'Individual' && (isset($params['current_employer']) || isset($params['employer_id']))) {
         // Create current employer.
         $newEmployer = !empty($params['employer_id']) ? $params['employer_id'] : CRM_Utils_Array::value('current_employer', $params);
         $newContact = FALSE;
         if (empty($params['contact_id'])) {
             $newContact = TRUE;
         }
         if ($newEmployer) {
             CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id, $newEmployer, $employerId, $newContact);
         } else {
             if ($employerId) {
                 CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($contact->id, $employerId);
             }
         }
     }
     // Update cached employer name.
     if ($contact->contact_type == 'Organization') {
         CRM_Contact_BAO_Contact_Utils::updateCurrentEmployer($contact->id);
     }
     return $contact;
 }
示例#5
0
 /**
  * Update the email value for the contact and user profile.
  *
  * @param int $contactId
  *   Contact ID of the user.
  * @param string $emailAddress
  *   Email to be modified for the user.
  */
 public static function updateContactEmail($contactId, $emailAddress)
 {
     $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
     $emailAddress = $strtolower($emailAddress);
     $ufmatch = new CRM_Core_DAO_UFMatch();
     $ufmatch->contact_id = $contactId;
     $ufmatch->domain_id = CRM_Core_Config::domainID();
     if ($ufmatch->find(TRUE)) {
         // Save the email in UF Match table
         $ufmatch->uf_name = $emailAddress;
         CRM_Core_BAO_UFMatch::create((array) $ufmatch);
         //check if the primary email for the contact exists
         //$contactDetails[1] - email
         //$contactDetails[3] - email id
         $contactDetails = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactId);
         if (trim($contactDetails[1])) {
             $emailID = $contactDetails[3];
             //update if record is found
             $query = "UPDATE  civicrm_email\n                     SET email = %1\n                     WHERE id =  %2";
             $p = array(1 => array($emailAddress, 'String'), 2 => array($emailID, 'Integer'));
             $dao = CRM_Core_DAO::executeQuery($query, $p);
         } else {
             //else insert a new email record
             $email = new CRM_Core_DAO_Email();
             $email->contact_id = $contactId;
             $email->is_primary = 1;
             $email->email = $emailAddress;
             $email->save();
             $emailID = $email->id;
         }
         CRM_Core_BAO_Log::register($contactId, 'civicrm_email', $emailID);
     }
 }
 /**
  * Process the user submitted custom data values.
  */
 public function postProcess()
 {
     // Get the form values and groupTree
     //CRM-18183
     $params = $this->controller->exportValues($this->_name);
     CRM_Core_BAO_CustomValueTable::postProcess($params, 'civicrm_contact', $this->_tableID, $this->_entityType);
     $table = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_groupID, 'table_name');
     $cgcount = CRM_Core_BAO_CustomGroup::customGroupDataExistsForEntity($this->_tableID, $table, TRUE);
     $cgcount += 1;
     $buttonName = $this->controller->getButtonName();
     if ($buttonName == $this->getButtonName('upload', 'new')) {
         CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/contact/view/cd/edit', "reset=1&type={$this->_contactType}&groupID={$this->_groupID}&entityID={$this->_tableID}&cgcount={$cgcount}&multiRecordDisplay=single&mode=add"));
     }
     // Add entry in the log table
     CRM_Core_BAO_Log::register($this->_tableID, 'civicrm_contact', $this->_tableID);
     if (CRM_Core_Resources::isAjaxMode()) {
         $this->ajaxResponse += CRM_Contact_Form_Inline::renderFooter($this->_tableID);
     }
     // reset the group contact cache for this group
     CRM_Contact_BAO_GroupContactCache::remove();
 }
示例#7
0
/**
 * Set a single value using the api.
 *
 * This function is called when no specific setvalue api exists.
 * Params must contain at least id=xx & {one of the fields from getfields}=value
 *
 * @param array $apiRequest
 *
 * @throws API_Exception
 * @return array
 */
function civicrm_api3_generic_setValue($apiRequest)
{
    $entity = $apiRequest['entity'];
    $params = $apiRequest['params'];
    $id = $params['id'];
    if (!is_numeric($id)) {
        return civicrm_api3_create_error(ts('Please enter a number'), array('error_code' => 'NaN', 'field' => "id"));
    }
    $field = CRM_Utils_String::munge($params['field']);
    $value = $params['value'];
    $fields = civicrm_api($entity, 'getFields', array('version' => 3, 'action' => 'create', "sequential"));
    // getfields error, shouldn't happen.
    if ($fields['is_error']) {
        return $fields;
    }
    $fields = $fields['values'];
    $isCustom = strpos($field, 'custom_') === 0;
    // Trim off the id portion of a multivalued custom field name
    $fieldKey = $isCustom && substr_count($field, '_') > 1 ? rtrim(rtrim($field, '1234567890'), '_') : $field;
    if (!array_key_exists($fieldKey, $fields)) {
        return civicrm_api3_create_error("Param 'field' ({$field}) is invalid. must be an existing field", array("error_code" => "invalid_field", "fields" => array_keys($fields)));
    }
    $def = $fields[$fieldKey];
    $title = CRM_Utils_Array::value('title', $def, ts('Field'));
    // Disallow empty values except for the number zero.
    // TODO: create a utility for this since it's needed in many places
    if (!empty($def['required']) || !empty($def['is_required'])) {
        if ((empty($value) || $value === 'null') && $value !== '0' && $value !== 0) {
            return civicrm_api3_create_error(ts('%1 is a required field.', array(1 => $title)), array("error_code" => "required", "field" => $field));
        }
    }
    switch ($def['type']) {
        case CRM_Utils_Type::T_FLOAT:
            if (!is_numeric($value) && !empty($value) && $value !== 'null') {
                return civicrm_api3_create_error(ts('%1 must be a number.', array(1 => $title)), array('error_code' => 'NaN'));
            }
            break;
        case CRM_Utils_Type::T_INT:
            if (!CRM_Utils_Rule::integer($value) && !empty($value) && $value !== 'null') {
                return civicrm_api3_create_error(ts('%1 must be a number.', array(1 => $title)), array('error_code' => 'NaN'));
            }
            break;
        case CRM_Utils_Type::T_STRING:
        case CRM_Utils_Type::T_TEXT:
            if (!CRM_Utils_Rule::xssString($value)) {
                return civicrm_api3_create_error(ts('Illegal characters in input (potential scripting attack)'), array('error_code' => 'XSS'));
            }
            if (array_key_exists('maxlength', $def)) {
                $value = substr($value, 0, $def['maxlength']);
            }
            break;
        case CRM_Utils_Type::T_DATE:
            $value = CRM_Utils_Type::escape($value, "Date", FALSE);
            if (!$value) {
                return civicrm_api3_create_error("Param '{$field}' is not a date. format YYYYMMDD or YYYYMMDDHHMMSS");
            }
            break;
        case CRM_Utils_Type::T_BOOLEAN:
            // Allow empty value for non-required fields
            if ($value === '' || $value === 'null') {
                $value = '';
            } else {
                $value = (bool) $value;
            }
            break;
        default:
            return civicrm_api3_create_error("Param '{$field}' is of a type not managed yet (" . $def['type'] . "). Join the API team and help us implement it", array('error_code' => 'NOT_IMPLEMENTED'));
    }
    $dao_name = _civicrm_api3_get_DAO($entity);
    $params = array('id' => $id, $field => $value);
    if ((!empty($def['pseudoconstant']) || !empty($def['option_group_id'])) && $value !== '' && $value !== 'null') {
        _civicrm_api3_api_match_pseudoconstant($params[$field], $entity, $field, $def);
    }
    CRM_Utils_Hook::pre('edit', $entity, $id, $params);
    // Custom fields
    if ($isCustom) {
        CRM_Utils_Array::crmReplaceKey($params, 'id', 'entityID');
        // Treat 'null' as empty value. This is awful but the rest of the code supports it.
        if ($params[$field] === 'null') {
            $params[$field] = '';
        }
        CRM_Core_BAO_CustomValueTable::setValues($params);
        CRM_Utils_Hook::post('edit', $entity, $id, CRM_Core_DAO::$_nullObject);
    } elseif (CRM_Core_DAO::setFieldValue($dao_name, $id, $field, $params[$field])) {
        $entityDAO = new $dao_name();
        $entityDAO->copyValues($params);
        CRM_Utils_Hook::post('edit', $entity, $entityDAO->id, $entityDAO);
    } else {
        return civicrm_api3_create_error("error assigning {$field}={$value} for {$entity} (id={$id})");
    }
    // Add changelog entry - TODO: Should we do this for other entities as well?
    if (strtolower($entity) === 'contact') {
        CRM_Core_BAO_Log::register($id, 'civicrm_contact', $id);
    }
    return civicrm_api3_create_success($params);
}
 /**
  * process the form
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $params = $this->exportValues();
     // need to process / save emails
     $params['contact_id'] = $this->_contactId;
     $params['updateBlankLocInfo'] = TRUE;
     // save email changes
     CRM_Core_BAO_Block::create('email', $params);
     // make entry in log table
     CRM_Core_BAO_Log::register($this->_contactId, 'civicrm_contact', $this->_contactId);
     $response = array('status' => 'save');
     $this->postProcessHook();
     echo json_encode($response);
     CRM_Utils_System::civiExit();
 }
示例#9
0
文件: Note.php 项目: bhirsch/voipdev
 /**
  * takes an associative array and creates a note object
  *
  * the function extract all the params it needs to initialize the create a
  * note object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array  $params         (reference ) an assoc array of name/value pairs
  *
  * @return object CRM_Core_BAO_Note object
  * @access public
  * @static
  */
 static function &add(&$params, $ids)
 {
     $dataExists = self::dataExists($params);
     if (!$dataExists) {
         return CRM_Core_DAO::$_nullObject;
     }
     $note =& new CRM_Core_BAO_Note();
     $params['modified_date'] = date("Ymd");
     $note->copyValues($params);
     if (!$params['contact_id']) {
         if ($params['entity_table'] == 'civicrm_contact') {
             $note->contact_id = $params['entity_id'];
         } else {
             CRM_Core_Error::statusBounce(ts('We could not find your logged in user ID'));
         }
     }
     if (CRM_Utils_Array::value('id', $ids)) {
         $note->id = CRM_Utils_Array::value('id', $ids);
     }
     $note->save();
     if ($note->entity_table == 'civicrm_contact') {
         require_once 'CRM/Core/BAO/Log.php';
         CRM_Core_BAO_Log::register($note->entity_id, 'civicrm_note', $note->id);
         require_once 'CRM/Contact/BAO/Contact.php';
         $displayName = CRM_Contact_BAO_Contact::displayName($note->entity_id);
         // add the recently created Note
         require_once 'CRM/Utils/Recent.php';
         CRM_Utils_Recent::add($displayName . ' - ' . $note->subject, CRM_Utils_System::url('civicrm/contact/view/note', "reset=1&action=view&cid={$note->entity_id}&id={$note->id}&context=home"), $note->id, 'Note', $note->entity_id, $displayName);
     }
     return $note;
 }
示例#10
0
 /**
  * takes an associative array and creates a note object
  *
  * the function extract all the params it needs to initialize the create a
  * note object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array  $params         (reference ) an assoc array of name/value pairs
  *
  * @return object CRM_Core_BAO_Note object
  * @access public
  * @static
  */
 static function &add(&$params, $ids)
 {
     $dataExists = self::dataExists($params);
     if (!$dataExists) {
         return CRM_Core_DAO::$_nullObject;
     }
     $note = new CRM_Core_BAO_Note();
     if (!isset($params['modified_date'])) {
         $params['modified_date'] = date("Ymd");
     }
     if (!isset($params['privacy'])) {
         $params['privacy'] = 0;
     }
     $note->copyValues($params);
     if (!$params['contact_id']) {
         if ($params['entity_table'] == 'civicrm_contact') {
             $note->contact_id = $params['entity_id'];
         } else {
             CRM_Core_Error::statusBounce(ts('We could not find your logged in user ID'));
         }
     }
     if (CRM_Utils_Array::value('id', $ids)) {
         $note->id = CRM_Utils_Array::value('id', $ids);
     }
     $note->save();
     if ($note->entity_table == 'civicrm_contact') {
         require_once 'CRM/Core/BAO/Log.php';
         CRM_Core_BAO_Log::register($note->entity_id, 'civicrm_note', $note->id);
         require_once 'CRM/Contact/BAO/Contact.php';
         $displayName = CRM_Contact_BAO_Contact::displayName($note->entity_id);
         $noteActions = false;
         $session = CRM_Core_Session::singleton();
         if ($session->get('userID')) {
             require_once 'CRM/Contact/BAO/Contact/Permission.php';
             if ($session->get('userID') == $note->entity_id) {
                 $noteActions = true;
             } else {
                 if (CRM_Contact_BAO_Contact_Permission::allow($note->entity_id, CRM_Core_Permission::EDIT)) {
                     $noteActions = true;
                 }
             }
         }
         $recentOther = array();
         if ($noteActions) {
             $recentOther = array('editUrl' => CRM_Utils_System::url('civicrm/contact/view/note', "reset=1&action=update&cid={$note->entity_id}&id={$note->id}&context=home"), 'deleteUrl' => CRM_Utils_System::url('civicrm/contact/view/note', "reset=1&action=delete&cid={$note->entity_id}&id={$note->id}&context=home"));
         }
         // add the recently created Note
         require_once 'CRM/Utils/Recent.php';
         CRM_Utils_Recent::add($displayName . ' - ' . $note->subject, CRM_Utils_System::url('civicrm/contact/view/note', "reset=1&action=view&cid={$note->entity_id}&id={$note->id}&context=home"), $note->id, 'Note', $note->entity_id, $displayName, $recentOther);
     }
     return $note;
 }
示例#11
0
 /**
  * takes an associative array and creates a contact object
  *
  * the function extract all the params it needs to initialize the create a
  * contact object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array  $params (reference ) an assoc array of name/value pairs
  *
  * @return object CRM_Contact_BAO_Contact object
  * @access public
  * @static
  */
 static function add(&$params)
 {
     $contact =& new CRM_Contact_DAO_Contact();
     if (empty($params)) {
         return;
     }
     //fixed contact source
     if (isset($params['contact_source'])) {
         $params['source'] = $params['contact_source'];
     }
     //fix for preferred communication method
     $prefComm = CRM_Utils_Array::value('preferred_communication_method', $params);
     if ($prefComm && is_array($prefComm)) {
         unset($params['preferred_communication_method']);
         $newPref = array();
         foreach ($prefComm as $k => $v) {
             if ($v) {
                 $newPref[$k] = $v;
             }
         }
         $prefComm = $newPref;
         if (is_array($prefComm) && !empty($prefComm)) {
             $prefComm = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, array_keys($prefComm)) . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR;
             $contact->preferred_communication_method = $prefComm;
         } else {
             $contact->preferred_communication_method = '';
         }
     }
     $allNull = $contact->copyValues($params);
     $contact->id = CRM_Utils_Array::value('contact_id', $params);
     if ($contact->contact_type == 'Individual') {
         $allNull = false;
         //format individual fields
         require_once "CRM/Contact/BAO/Individual.php";
         CRM_Contact_BAO_Individual::format($params, $contact);
     } else {
         if ($contact->contact_type == 'Household') {
             if (isset($params['household_name'])) {
                 $allNull = false;
                 $contact->display_name = $contact->sort_name = CRM_Utils_Array::value('household_name', $params, '');
             }
         } else {
             if ($contact->contact_type == 'Organization') {
                 if (isset($params['organization_name'])) {
                     $allNull = false;
                     $contact->display_name = $contact->sort_name = CRM_Utils_Array::value('organization_name', $params, '');
                 }
             }
         }
     }
     // privacy block
     $privacy = CRM_Utils_Array::value('privacy', $params);
     if ($privacy && is_array($privacy) && !empty($privacy)) {
         $allNull = false;
         foreach (self::$_commPrefs as $name) {
             $contact->{$name} = CRM_Utils_Array::value($name, $privacy, false);
         }
     }
     // since hash was required, make sure we have a 0 value for it, CRM-1063
     // fixed in 1.5 by making hash optional
     // only do this in create mode, not update
     if ((!array_key_exists('hash', $contact) || !$contact->hash) && !$contact->id) {
         $allNull = false;
         $contact->hash = md5(uniqid(rand(), true));
     }
     if (!$allNull) {
         $contact->save();
         require_once 'CRM/Core/BAO/Log.php';
         CRM_Core_BAO_Log::register($contact->id, 'civicrm_contact', $contact->id);
     }
     if ($contact->contact_type == 'Individual' && array_key_exists('current_employer', $params)) {
         // create current employer
         if ($params['current_employer']) {
             require_once 'CRM/Contact/BAO/Contact/Utils.php';
             CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id, $params['current_employer']);
         } else {
             //unset if employer id exits
             if ($employerId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contact->id, 'employer_id')) {
                 require_once 'CRM/Contact/BAO/Contact/Utils.php';
                 CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($contact->id, $employerId);
             }
         }
     }
     //update cached employee name
     if ($contact->contact_type == 'Organization') {
         require_once 'CRM/Contact/BAO/Contact/Utils.php';
         CRM_Contact_BAO_Contact_Utils::updateCurrentEmployer($contact->id);
     }
     // process greetings CRM-4575, cache greetings
     self::processGreetings($contact);
     return $contact;
 }