/** * @param string $sEmail * @param string $mID * @param bool $bIsStrID = false * * @return \RainLoop\Providers\AddressBook\Classes\Contact|null */ public function GetContactByID($sEmail, $mID, $bIsStrID = false) { $mID = \trim($mID); $iUserID = $this->getUserId($sEmail); $sSql = 'SELECT * FROM rainloop_ab_contacts WHERE deleted = 0 AND id_user = :id_user'; $aParams = array(':id_user' => array($iUserID, \PDO::PARAM_INT)); if ($bIsStrID) { $sSql .= ' AND id_contact_str = :id_contact_str'; $aParams[':id_contact_str'] = array($mID, \PDO::PARAM_STR); } else { $sSql .= ' AND id_contact = :id_contact'; $aParams[':id_contact'] = array($mID, \PDO::PARAM_INT); } $sSql .= ' LIMIT 1'; $oContact = null; $iIdContact = 0; $oStmt = $this->prepareAndExecute($sSql, $aParams); if ($oStmt) { $aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC); if (\is_array($aFetch) && 0 < \count($aFetch)) { foreach ($aFetch as $aItem) { $iIdContact = $aItem && isset($aItem['id_contact']) ? (int) $aItem['id_contact'] : 0; if (0 < $iIdContact) { $oContact = new \RainLoop\Providers\AddressBook\Classes\Contact(); $oContact->IdContact = (string) $iIdContact; $oContact->IdContactStr = isset($aItem['id_contact_str']) ? (string) $aItem['id_contact_str'] : ''; $oContact->Display = isset($aItem['display']) ? (string) $aItem['display'] : ''; $oContact->Changed = isset($aItem['changed']) ? (int) $aItem['changed'] : 0; $oContact->ReadOnly = $iUserID !== (isset($aItem['id_user']) ? (int) $aItem['id_user'] : 0); $oContact->Etag = empty($aItem['etag']) ? '' : (string) $aItem['etag']; } } } unset($aFetch); if (0 < $iIdContact && $oContact) { $oStmt->closeCursor(); $sSql = 'SELECT * FROM rainloop_ab_properties WHERE id_contact = ' . $iIdContact; $oStmt = $this->prepareAndExecute($sSql); if ($oStmt) { $aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC); if (\is_array($aFetch) && 0 < \count($aFetch)) { foreach ($aFetch as $aItem) { if ($aItem && isset($aItem['id_prop'], $aItem['id_contact'], $aItem['prop_type'], $aItem['prop_value'])) { if ((string) $oContact->IdContact === (string) $aItem['id_contact']) { $oProperty = new \RainLoop\Providers\AddressBook\Classes\Property(); $oProperty->IdProperty = (int) $aItem['id_prop']; $oProperty->Type = (int) $aItem['prop_type']; $oProperty->TypeStr = isset($aItem['prop_type_str']) ? (string) $aItem['prop_type_str'] : ''; $oProperty->Value = (string) $aItem['prop_value']; $oProperty->ValueCustom = isset($aItem['prop_value_custom']) ? (string) $aItem['prop_value_custom'] : ''; $oProperty->Frec = isset($aItem['prop_frec']) ? (int) $aItem['prop_frec'] : 0; $oContact->Properties[] = $oProperty; } } } } unset($aFetch); $oContact->UpdateDependentValues(); } } } return $oContact; }
/** * @return array */ public function DoContactSave() { $oAccount = $this->getAccountFromToken(); $bResult = false; $oAddressBookProvider = $this->AddressBookProvider($oAccount); $sRequestUid = \trim($this->GetActionParam('RequestUid', '')); if ($oAddressBookProvider && $oAddressBookProvider->IsActive() && 0 < \strlen($sRequestUid)) { $sUid = \trim($this->GetActionParam('Uid', '')); $oContact = null; if (0 < \strlen($sUid)) { $oContact = $oAddressBookProvider->GetContactByID($oAccount->ParentEmailHelper(), $sUid); } if (!$oContact) { $oContact = new \RainLoop\Providers\AddressBook\Classes\Contact(); if (0 < \strlen($sUid)) { $oContact->IdContact = $sUid; } } $oContact->Properties = array(); $aProperties = $this->GetActionParam('Properties', array()); if (\is_array($aProperties)) { foreach ($aProperties as $aItem) { if ($aItem && isset($aItem[0], $aItem[1]) && \is_numeric($aItem[0])) { $oProp = new \RainLoop\Providers\AddressBook\Classes\Property(); $oProp->Type = (int) $aItem[0]; $oProp->Value = $aItem[1]; $oProp->TypeStr = empty($aItem[2]) ? '' : $aItem[2]; $oContact->Properties[] = $oProp; } } } if (!empty($oContact->Etag)) { $oContact->Etag = \md5($oContact->ToVCard()); } $oContact->PopulateDisplayAndFullNameValue(true); $bResult = $oAddressBookProvider->ContactSave($oAccount->ParentEmailHelper(), $oContact); } return $this->DefaultResponse(__FUNCTION__, array('RequestUid' => $sRequestUid, 'ResultID' => $bResult ? $oContact->IdContact : '', 'Result' => $bResult)); }
/** * @param string $sEmail * @param string $sVcfData * * @return int */ public function ImportVcfFile($sEmail, $sVcfData) { $iCount = 0; if ($this->IsActive() && \is_string($sVcfData)) { $sVcfData = \trim($sVcfData); if ("" === \substr($sVcfData, 0, 3)) { $sVcfData = \substr($sVcfData, 3); } $oVCardSplitter = null; try { $oVCardSplitter = new \Sabre\VObject\Splitter\VCard($sVcfData); } catch (\Exception $oExc) { $this->Logger()->WriteException($oExc); } if ($oVCardSplitter) { $oContact = new \RainLoop\Providers\AddressBook\Classes\Contact(); $oVCard = null; while ($oVCard = $oVCardSplitter->getNext()) { if ($oVCard instanceof \Sabre\VObject\Component\VCard) { \MailSo\Base\Utils::ResetTimeLimit(); if (empty($oVCard->UID)) { $oVCard->UID = \Sabre\DAV\UUIDUtil::getUUID(); } $oContact->PopulateByVCard($oVCard->serialize()); if (0 < \count($oContact->Properties)) { if ($this->ContactSave($sEmail, $oContact)) { $iCount++; } } $oContact->Clear(); } } } } return $iCount; }