protected function _ReplaceContact(FunambolContactContainer $fnContactContainer)
 {
     if ($fnContactContainer->getValue('id') == null) {
         $ids = $this->query($this->_commandCreator->CreateContactId($fnContactContainer));
         $fnContactContainer->SetValue('id', -1);
         if (isset($ids) && count($ids) > 0) {
             if (isset($ids[0]['min_id']) && $ids[0]['min_id'] < 0) {
                 $fnContactContainer->SetValue('id', $ids[0]['min_id'] - 1);
             }
         }
     }
     if ($this->_executeSql($this->_commandCreator->ReplaceContact($fnContactContainer))) {
         return true;
     }
     return false;
 }
 private function ConvertWMToFunambolContactContainer(&$wmContactContainer, $updateDate = FALSE)
 {
     $fnContactContainer = new FunambolContactContainer();
     $funambol_user = $this->_account->Email;
     $fnContactContainer->SetValue('id', $wmContactContainer->GetValue('FunambolContactId'));
     $fnContactContainer->SetValue('userid', $funambol_user);
     if ($wmContactContainer->GetValue('Deleted') == 1) {
         $fnContactContainer->SetValue('status', FUNAMBOL_STATUS_DELETED);
     } else {
         $fnContactContainer->SetValue('status', FUNAMBOL_STATUS_UPDATED);
     }
     if ($updateDate) {
         $wmDateModified = $wmContactContainer->GetValue('DateModified');
         // as 2000-12-31 23:59:59
         $wmTimestampModified = strtotime($wmDateModified);
         $fnTimestampModified = $wmTimestampModified + date('Z');
         // as seconds from Epoch in localtime
         $fnContactContainer->SetValue('last_update', "" . $fnTimestampModified . "111");
     } else {
         $fnContactContainer->SetValue('last_update', "" . time() . "222");
     }
     $fnContactContainer->SetValue('title', $wmContactContainer->GetValue('Title'));
     $fnContactContainer->SetValue('subject', $wmContactContainer->GetValue('FullName'));
     $wm_fname = $wmContactContainer->GetValue('FirstName');
     $wm_sname = $wmContactContainer->GetValue('SurName');
     $wm_full = $wmContactContainer->GetValue('FullName');
     if (empty($wm_fname) && empty($wm_sname) && !empty($wm_full)) {
         // actually, this is typical situation when coping data from WM
         // copy FullName as first_name
         // leave last_name empty
         // and get user define himself what part of 'FullName' should be
         // copied to last_name
         $lname = NULL;
         $fname = NULL;
         $parts = explode(' ', trim($wmContactContainer->GetValue('FullName')));
         // expecting line as FirstName LastName
         if (count($parts) > 0) {
             $fname = array_shift($parts);
             $lname = implode(' ', $parts);
             //				if(is_null($lname)) $lname='';
             //				if(is_null($fname)) $fname='';
         }
         $fnContactContainer->SetValue('first_name', $fname);
         $fnContactContainer->SetValue('last_name', $lname);
         //			$fnContactContainer->SetValue('first_name',			$wmContactContainer->GetValue('FullName'));
         //			$fnContactContainer->SetValue('last_name',			'');
     } else {
         $fnContactContainer->SetValue('first_name', $wmContactContainer->GetValue('FirstName'));
         $fnContactContainer->SetValue('last_name', $wmContactContainer->GetValue('SurName'));
     }
     $fnContactContainer->SetValue('display_name', $wmContactContainer->GetValue('FullName'));
     $fnContactContainer->SetValue('nickname', $wmContactContainer->GetValue('NickName'));
     $fnContactContainer->SetValue('body', $wmContactContainer->GetValue('Notes'));
     //	$fnContactContainer->SetValue('UseFriendlyName',	1);
     $fnContactContainer->SetValue('HomeStreet', $wmContactContainer->GetValue('HomeStreet'));
     $fnContactContainer->SetValue('HomeCity', $wmContactContainer->GetValue('HomeCity'));
     $fnContactContainer->SetValue('HomeState', $wmContactContainer->GetValue('HomeState'));
     $fnContactContainer->SetValue('HomeZip', $wmContactContainer->GetValue('HomeZip'));
     $fnContactContainer->SetValue('HomeCountry', $wmContactContainer->GetValue('HomeCountry'));
     $fnContactContainer->SetValue('HomePhone', $wmContactContainer->GetValue('HomePhone'));
     $fnContactContainer->SetValue('HomeFax', $wmContactContainer->GetValue('HomeFax'));
     $fnContactContainer->SetValue('HomeMobile', $wmContactContainer->GetValue('HomeMobile'));
     $fnContactContainer->SetValue('HomeEmail', $wmContactContainer->GetValue('HomeEmail'));
     $fnContactContainer->SetValue('HomeWeb', $wmContactContainer->GetValue('HomeWeb'));
     $fnContactContainer->SetValue('BusinessEmail', $wmContactContainer->GetValue('BusinessEmail'));
     $fnContactContainer->SetValue('company', $wmContactContainer->GetValue('BusinessCompany'));
     $fnContactContainer->SetValue('BusinessStreet', $wmContactContainer->GetValue('BusinessStreet'));
     $fnContactContainer->SetValue('BusinessCity', $wmContactContainer->GetValue('BusinessCity'));
     $fnContactContainer->SetValue('BusinessState', $wmContactContainer->GetValue('BusinessZip'));
     $fnContactContainer->SetValue('BusinessZip', $wmContactContainer->GetValue('BusinessZip'));
     $fnContactContainer->SetValue('BusinessCountry', $wmContactContainer->GetValue('BusinessCountry'));
     $fnContactContainer->SetValue('job_title', $wmContactContainer->GetValue('BusinessJobTitle'));
     $fnContactContainer->SetValue('department', $wmContactContainer->GetValue('BusinessDepartment'));
     $fnContactContainer->SetValue('office_location', $wmContactContainer->GetValue('BusinessOffice'));
     $fnContactContainer->SetValue('companies', $wmContactContainer->GetValue('BusinessCompany'));
     $fnContactContainer->SetValue('BusinessPhone', $wmContactContainer->GetValue('BusinessPhone'));
     //	$fmContactContainer->SetValue('BusinessMobile',		$wmContactContainer->GetValue(''));
     $fnContactContainer->SetValue('BusinessFax', $wmContactContainer->GetValue('BusinessFax'));
     //	$fmContactContainer->SetValue('BusinessWeb',);
     $fnContactContainer->SetValue('OtherEmail', $wmContactContainer->GetValue('OtherEmail'));
     //	$fmContactContainer->SetValue('PrimaryEmail',);
     //		$this->_container['IdPreviousAddress'] = null;
     //		$this->_container['Temp'] = null;
     $tmp = $wmContactContainer->GetValue('BirthdayYear') . "-" . $wmContactContainer->GetValue('BirthdayMonth') . "-" . $wmContactContainer->GetValue('BirthdayDay');
     if (strlen($tmp) == 10) {
         // 2010-12-31 looks like live date
         $fnContactContainer->SetValue('birthday', $tmp);
     }
     //		$this->_container['DateCreated'] = null;
     //		$this->_container['DateModified'] = null;
     return $fnContactContainer;
 }