Added functionality to share contacts

Added setting "Automatically add recipients to your address beech"
Further development of editing screen contact
This commit is contained in:
RainLoop Team 2013-12-19 04:53:42 +04:00
parent 026839d864
commit 2d9ff7d63f
63 changed files with 1229 additions and 1919 deletions

View file

@ -562,6 +562,9 @@ class Actions
{
$this->oPersonalAddressBookProvider = new \RainLoop\Providers\PersonalAddressBook(
$this->Config()->Get('contacts', 'enable', false) || $bForceEnable ? $this->fabrica('personal-address-book', $oAccount) : null);
$this->oPersonalAddressBookProvider->ConsiderShare(
!!$this->Config()->Get('contacts', 'allow_sharing', false));
}
else if ($oAccount && $this->oPersonalAddressBookProvider->IsSupported())
{
@ -932,6 +935,7 @@ class Actions
$aResult['AccountHash'] = $oAccount->Hash();
$aResult['ChangePasswordIsAllowed'] = $this->ChangePasswordProvider()->PasswordChangePossibility($oAccount);
$aResult['ContactsIsAllowed'] = $this->PersonalAddressBookProvider($oAccount)->IsActive();
$aResult['ContactsSharingIsAllowed'] = $this->PersonalAddressBookProvider($oAccount)->IsSharingAllowed();
$oSettings = $this->SettingsProvider()->Load($oAccount);
}
@ -990,6 +994,7 @@ class Actions
$aResult['PostgreSqlIsSupported'] = \is_array($aDrivers) ? \in_array('pgsql', $aDrivers) : false;
$aResult['ContactsEnable'] = (bool) $oConfig->Get('contacts', 'enable', false);
$aResult['ContactsSharing'] = (bool) $oConfig->Get('contacts', 'allow_sharing', false);
$aResult['ContactsPdoType'] = $this->ValidateContactPdoType(\trim($this->Config()->Get('contacts', 'type', 'sqlite')));
$aResult['ContactsPdoDsn'] = (string) $oConfig->Get('contacts', 'pdo_dsn', '');
$aResult['ContactsPdoType'] = (string) $oConfig->Get('contacts', 'type', '');
@ -1033,6 +1038,7 @@ class Actions
// user
$aResult['EditorDefaultType'] = (string) $oConfig->Get('webmail', 'editor_default_type', '');
$aResult['ShowImages'] = (bool) $oConfig->Get('webmail', 'show_images', false);
$aResult['ContactsAutosave'] = true;
$aResult['MPP'] = (int) $oConfig->Get('webmail', 'messages_per_page', 25);
$aResult['DesktopNotifications'] = false;
$aResult['UseThreads'] = false;
@ -1066,6 +1072,7 @@ class Actions
$aResult['NullFolder'] = $oSettings->GetConf('NullFolder', '');
$aResult['EditorDefaultType'] = $oSettings->GetConf('EditorDefaultType', $aResult['EditorDefaultType']);
$aResult['ShowImages'] = (bool) $oSettings->GetConf('ShowImages', $aResult['ShowImages']);
$aResult['ContactsAutosave'] = (bool) $oSettings->GetConf('ContactsAutosave', $aResult['ContactsAutosave']);
$aResult['MPP'] = (int) $oSettings->GetConf('MPP', $aResult['MPP']);
$aResult['DesktopNotifications'] = (bool) $oSettings->GetConf('DesktopNotifications', $aResult['DesktopNotifications']);
$aResult['UseThreads'] = (bool) $oSettings->GetConf('UseThreads', $aResult['UseThreads']);
@ -1867,6 +1874,7 @@ class Actions
$this->setConfigFromParams($oConfig, 'LoginDefaultDomain', 'login', 'default_domain', 'string');
$this->setConfigFromParams($oConfig, 'ContactsEnable', 'contacts', 'enable', 'bool');
$this->setConfigFromParams($oConfig, 'ContactsSharing', 'contacts', 'allow_sharing', 'bool');
$this->setConfigFromParams($oConfig, 'ContactsPdoDsn', 'contacts', 'pdo_dsn', 'string');
$this->setConfigFromParams($oConfig, 'ContactsPdoUser', 'contacts', 'pdo_user', 'string');
$this->setConfigFromParams($oConfig, 'ContactsPdoPassword', 'contacts', 'pdo_password', 'dummy');
@ -3000,6 +3008,7 @@ class Actions
$this->setSettingsFromParams($oSettings, 'EditorDefaultType', 'string');
$this->setSettingsFromParams($oSettings, 'ShowImages', 'bool');
$this->setSettingsFromParams($oSettings, 'ContactsAutosave', 'bool');
$this->setSettingsFromParams($oSettings, 'InterfaceAnimation', 'string', function ($sValue) {
return (\in_array($sValue,
array(\RainLoop\Enumerations\InterfaceAnimation::NONE,
@ -4153,7 +4162,10 @@ class Actions
if (0 < \count($aArrayToFrec))
{
$this->PersonalAddressBookProvider($oAccount)->IncFrec($oAccount, \array_values($aArrayToFrec));
$oSettings = $this->SettingsProvider()->Load($oAccount);
$this->PersonalAddressBookProvider($oAccount)->IncFrec($oAccount, \array_values($aArrayToFrec),
!!$oSettings->GetConf('ContactsAutosave', false));
}
}
@ -4196,7 +4208,7 @@ class Actions
{
$iCount = 0;
$mResult = $this->PersonalAddressBookProvider($oAccount)->GetContacts($oAccount,
$iOffset, $iLimit, $sSearch, \RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_, $iCount);
$iOffset, $iLimit, $sSearch, $iCount);
}
return $this->DefaultResponse(__FUNCTION__, array(
@ -4244,6 +4256,13 @@ class Actions
if ($oPab && $oPab->IsActive() && 0 < \strlen($sRequestUid))
{
$sUid = \trim($this->GetActionParam('Uid', ''));
$iScopeType = (int) $this->GetActionParam('ScopeType', null);
if (!in_array($iScopeType, array(
\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_,
\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_ALL)))
{
$iScopeType = \RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_;
}
$oContact = new \RainLoop\Providers\PersonalAddressBook\Classes\Contact();
if (0 < \strlen($sUid))
@ -4251,6 +4270,8 @@ class Actions
$oContact->IdContact = $sUid;
}
$oContact->ScopeType = $iScopeType;
$aProperties = $this->GetActionParam('Properties', array());
if (\is_array($aProperties))
{
@ -4262,6 +4283,7 @@ class Actions
$oProp = new \RainLoop\Providers\PersonalAddressBook\Classes\Property();
$oProp->Type = (int) $aItem[0];
$oProp->Value = $aItem[1];
$oProp->ScopeType = $iScopeType;
$oContact->Properties[] = $oProp;
}
@ -5911,16 +5933,6 @@ class Actions
'Email' => \MailSo\Base\Utils::Utf8Clear($mResponse->GetEmail())
));
}
else if ('RainLoop\Providers\Contacts\Classes\Contact' === $sClassName)
{
$mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array(
'IdContact' => $mResponse->IdContact,
'ImageHash' => $mResponse->ImageHash,
'ListName' => \MailSo\Base\Utils::Utf8Clear($mResponse->ListName),
'Name' => \MailSo\Base\Utils::Utf8Clear($mResponse->Name),
'Emails' => $mResponse->Emails
));
}
else if ('RainLoop\Providers\PersonalAddressBook\Classes\Contact' === $sClassName)
{
$mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array(
@ -5929,7 +5941,6 @@ class Actions
'Display' => \MailSo\Base\Utils::Utf8Clear($mResponse->Display),
'ReadOnly' => $mResponse->ReadOnly,
'ScopeType' => $mResponse->ScopeType,
'ScopeValue' => $mResponse->ScopeValue,
'IdPropertyFromSearch' => $mResponse->IdPropertyFromSearch,
'Properties' => $this->responseObject($mResponse->Properties, $sParent, $aParameters)
));
@ -5942,7 +5953,7 @@ class Actions
'Type' => $mResponse->Type,
'TypeCustom' => $mResponse->TypeCustom,
'Value' => \MailSo\Base\Utils::Utf8Clear($mResponse->Value),
'ValueClear' => \MailSo\Base\Utils::Utf8Clear($mResponse->ValueClear)
'ValueCustom' => \MailSo\Base\Utils::Utf8Clear($mResponse->ValueCustom)
));
}
else if ('MailSo\Mail\Attachment' === $sClassName)

View file

@ -83,6 +83,7 @@ class Application extends \RainLoop\Config\AbstractConfig
'contacts' => array(
'enable' => array(false, 'Enable contacts'),
'allow_sharing' => array(true),
'suggestions_limit' => array(30),
'type' => array('sqlite', ''),
'pdo_dsn' => array('mysql:host=127.0.0.1;port=3306;dbname=rainloop', ''),

View file

@ -1,121 +0,0 @@
<?php
namespace RainLoop\Providers;
class Contacts extends \RainLoop\Providers\AbstractProvider
{
/**
* @var \RainLoop\Providers\Contacts\ContactsInterface
*/
private $oDriver;
/**
* @param \RainLoop\Providers\Contacts\ContactsInterface $oDriver
*
* @return void
*/
public function __construct($oDriver)
{
$this->oDriver = null;
if ($oDriver instanceof \RainLoop\Providers\Contacts\ContactsInterface)
{
$this->oDriver = $oDriver;
}
}
/**
* @return bool
*/
public function IsActive()
{
return $this->oDriver instanceof \RainLoop\Providers\Contacts\ContactsInterface &&
$this->oDriver->IsSupported();
}
/**
* @return bool
*/
public function IsSupported()
{
return $this->oDriver instanceof \RainLoop\Providers\Contacts\ContactsInterface &&
$this->oDriver->IsSupported();
}
/**
* @param \RainLoop\Account $oAccount
* @param int $iIdContact
*
* @return array
*/
public function GetContactById($oAccount, $iIdContact)
{
return $this->oDriver ? $this->oDriver->GetContactById($oAccount, $iIdContact) : null;
}
/**
* @param \RainLoop\Account $oAccount
* @param int $iOffset = 0
* @param int $iLimit = 20
* @param string $sSearch = ''
*
* @return array
*/
public function GetContacts($oAccount, $iOffset = 0, $iLimit = 20, $sSearch = '')
{
return $this->oDriver ? $this->oDriver->GetContacts($oAccount, $iOffset, $iLimit, $sSearch) : array();
}
/**
* @param \RainLoop\Account $oAccount
*
* @return array
*/
public function GetContactsImageHashes($oAccount)
{
return $this->oDriver ? $this->oDriver->GetContactsImageHashes($oAccount) : array();
}
/**
* @param \RainLoop\Account $oAccount
* @param \RainLoop\Providers\Contacts\Classes\Contact $oContact
*
* @return bool
*/
public function CreateContact($oAccount, &$oContact)
{
return $this->oDriver ? $this->oDriver->CreateContact($oAccount, $oContact) : false;
}
/**
* @param \RainLoop\Account $oAccount
* @param \RainLoop\Providers\Contacts\Classes\Contact $oContact
*
* @return bool
*/
public function UpdateContact($oAccount, &$oContact)
{
return $this->oDriver ? $this->oDriver->UpdateContact($oAccount, $oContact) : false;
}
/**
* @param \RainLoop\Account $oAccount
* @param array $aContactIds
*
* @return bool
*/
public function DeleteContacts($oAccount, $aContactIds)
{
return $this->oDriver ? $this->oDriver->DeleteContacts($oAccount, $aContactIds) : false;
}
/**
* @param \RainLoop\Account $oAccount
* @param array $aContactIds
*
* @return bool
*/
public function IncFrec($oAccount, $aContactIds)
{
return $this->oDriver ? $this->oDriver->IncFrec($oAccount, $aContactIds) : false;
}
}

View file

@ -1,111 +0,0 @@
<?php
namespace RainLoop\Providers\Contacts\Classes;
class Contact
{
/**
* @var int
*/
public $IdContact;
/**
* @var int
*/
public $IdUser;
/**
* @var int
*/
public $Type;
/**
* @var int
*/
public $Frec;
/**
* @var string
*/
public $ListName;
/**
* @var string
*/
public $Name;
/**
* @var array
*/
public $Emails;
/**
* @var string
*/
public $ImageHash;
/**
* @var array
*/
public $Data;
public function __construct()
{
$this->Clear();
}
public function Clear()
{
$this->IdContact = 0;
$this->IdUser = 0;
$this->Type = 0;
$this->Frec = 0;
$this->ListName = '';
$this->Name = '';
$this->ImageHash = '';
$this->Emails = array();
$this->Data = array();
}
/**
* @return string
*/
public function GenarateListName()
{
return 0 < \strlen($this->Name) ? $this->Name : (!empty($this->Emails[0]) ? $this->Emails[0] : '');
}
/**
* @return string
*/
public function EmailsAsString()
{
return \trim(\implode(' ', $this->Emails));
}
/**
* @return string
*/
public function DataAsString()
{
return @\serialize($this->Data);
}
/**
* @param string $sData
*/
public function ParseData($sData)
{
$sData = (string) $sData;
$sData = \trim($sData);
if (!empty($sData))
{
$aData = @\unserialize($sData);
if (\is_array($aData))
{
$this->Data = $aData;
}
}
}
}

View file

@ -1,38 +0,0 @@
<?php
namespace RainLoop\Providers\Contacts\Classes;
class Db
{
/**
* @return int
*/
static public function Version()
{
return 1;
}
/**
* @return array
*/
static public function Strucure()
{
return array(
'rlContactsUsers' => array(
'IdUser' => 'INTEGER PRIMARY KEY',
'Email' => 'TEXT'
),
'rlContactsItems' => array(
'IdContact' => 'INTEGER PRIMARY KEY',
'IdUser' => 'INTEGER',
'Type' => 'INTEGER',
'Frec' => 'INTEGER',
'ImageHash' => 'TEXT',
'ListName' => 'TEXT',
'Name' => 'TEXT',
'Emails' => 'TEXT',
'Data' => 'TEXT'
)
);
}
}

View file

@ -1,68 +0,0 @@
<?php
namespace RainLoop\Providers\Contacts;
interface ContactsInterface
{
/**
* @param \RainLoop\Account $oAccount
* @param int $iIdContact
*
* @return $oContact|null
*/
public function GetContactById($oAccount, $iIdContact);
/**
* @param \RainLoop\Account $oAccount
* @param int $iOffset = 0
* @param int $iLimit = 20
* @param string $sSearch = ''
*
* @return array
*/
public function GetContacts($oAccount, $iOffset = 0, $iLimit = 20, $sSearch = '');
/**
* @param \RainLoop\Account $oAccount
*
* @return array
*/
public function GetContactsImageHashes($oAccount);
/**
* @param \RainLoop\Account $oAccount
* @param \RainLoop\Providers\Contacts\Classes\Contact $oContact
*
* @return bool
*/
public function CreateContact($oAccount, &$oContact);
/**
* @param \RainLoop\Account $oAccount
* @param \RainLoop\Providers\Contacts\Classes\Contact $oContact
*
* @return bool
*/
public function UpdateContact($oAccount, &$oContact);
/**
* @param \RainLoop\Account $oAccount
* @param array $aContactIds
*
* @return bool
*/
public function DeleteContacts($oAccount, $aContactIds);
/**
* @return bool
*/
public function IsSupported();
/**
* @param \RainLoop\Account $oAccount
* @param array $aContactIds
*
* @return bool
*/
public function IncFrec($oAccount, $aContactIds);
}

View file

@ -1,600 +0,0 @@
<?php
namespace RainLoop\Providers\Contacts;
class DefaultContacts implements \RainLoop\Providers\Contacts\ContactsInterface
{
/**
* @var \MailSo\Log\Logger
*/
private $oLogger;
/**
* @var bool
*/
private $bUseDbPerUser;
/**
* @param \MailSo\Log\Logger $oLogger = null
*/
public function __construct($oLogger = null)
{
$this->oLogger = $oLogger instanceof \MailSo\Log\Logger ? $oLogger : null;
$this->bUseDbPerUser = true;
}
/**
* @param \RainLoop\Account $oAccount
* @staticvar array $aPdoCache
* @return \PDO
*/
private function getPDO($oAccount)
{
static $aPdoCache = array();
$sEmail = $oAccount->ParentEmailHelper();
if (isset($aPdoCache[$sEmail]))
{
return $aPdoCache[$sEmail];
}
if (!\class_exists('PDO'))
{
throw new \Exception('class_exists=PDO');
}
$sVersionFile = '';
$sDsn = '';
if ($this->bUseDbPerUser)
{
$sSubPath = APP_PRIVATE_DATA.'storage/contacts/'.\rtrim(\substr($sEmail, 0, 2), '@').'/'.$sEmail.'/';
if (!\is_dir($sSubPath))
{
if (\mkdir($sSubPath, 0755, true) && \is_dir($sSubPath))
{
$sVersionFile = $sSubPath.'.version';
$sDsn = 'sqlite:'.$sSubPath.'contacts.sqlite';
}
}
else
{
$sVersionFile = $sSubPath.'.version';
$sDsn = 'sqlite:'.$sSubPath.'contacts.sqlite';
}
}
else
{
$sVersionFile = APP_PRIVATE_DATA.'.version';
$sDsn = 'sqlite:'.APP_PRIVATE_DATA.'contacts.sqlite';
}
$sDbLogin = '';
$sDbPassword = '';
$oPdo = false;
try
{
$oPdo = new \PDO($sDsn, $sDbLogin, $sDbPassword);
if ($oPdo)
{
$oPdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
if (!@\file_exists($sVersionFile) ||
(string) @file_get_contents($sVersionFile) !== (string) \RainLoop\Providers\Contacts\Classes\Db::Version())
{
$this->syncTables($oPdo, $sVersionFile);
}
$oPdo->sqliteCreateFunction('SIMPLESEARCH', function ($sEmailValue, $sNameValue, $sMask) {
return \preg_match('/'.\preg_quote($sMask, '/').'/ui',
$sEmailValue.' '.$sNameValue) ? 1 : 0;
});
}
}
catch (\Exception $oException)
{
throw $oException;
$oPdo = false;
}
if ($oPdo)
{
$aPdoCache[$oAccount->ParentEmailHelper()] = $oPdo;
}
return $oPdo;
}
protected function getWantedColumnsInfo($sTableName, $aCurrent)
{
$aColumns = array();
foreach ($aCurrent as $sName => $sType)
{
$sSql = $sName.' '.$sType;
switch ($sType)
{
case 'INTEGER':
$sSql .= ' DEFAILT \'0\'';
break;
case 'TEXT':
$sSql .= ' DEFAILT \'\'';
break;
}
$aColumns[$sName] = $sSql;
}
if (0 === \count($aColumns))
{
return '';
}
return 'CREATE TABLE '.$sTableName.' (' .\implode(', ', $aColumns).')';
}
/**
* @param \PDO $oAccount
* @param string $sTableName
*/
protected function getCurrentColumnsInfo($oPdo, $sTableName)
{
$oStmt = $this->prepareAndExecute($oPdo, 'SELECT `sql` FROM `sqlite_master` WHERE `tbl_name` = :TableName AND `type` = :Type', array(
':TableName' => array($sTableName, \PDO::PARAM_STR),
':Type' => array('table', \PDO::PARAM_STR)
));
if ($oStmt)
{
$mRow = $oStmt->fetch(\PDO::FETCH_ASSOC);
if ($mRow && isset($mRow['sql']))
{
return (string) $mRow['sql'];
}
}
return '';
}
/**
* @param \PDO $oPdo
* @param string $sVersionFile = ''
*/
private function syncTables($oPdo, $sVersionFile = '')
{
if ($this->oLogger)
{
$this->oLogger->Write('Start to sync', \MailSo\Log\Enumerations\Type::INFO);
}
$aStrucure = \RainLoop\Providers\Contacts\Classes\Db::Strucure();
foreach ($aStrucure as $sTableName => $aField)
{
$sCurrent = $this->getCurrentColumnsInfo($oPdo, $sTableName);
$sWanted = $this->getWantedColumnsInfo($sTableName, $aField);
if (empty($sCurrent))
{
$this->prepareAndExecute($oPdo, $sWanted);
}
else if ($sCurrent !== $sWanted)
{
$this->prepareAndExecute($oPdo, 'DROP TABLE IF EXISTS `'.$sTableName.'_old`');
$this->prepareAndExecute($oPdo, 'ALTER TABLE `'.$sTableName.'` RENAME TO `'.$sTableName.'_old`');
$this->prepareAndExecute($oPdo, $sWanted);
$aNewKeys = array();
$aOldKeys = array();
foreach ($aField as $sKey => $sType)
{
$aNewKeys[] = $sKey;
$aOldKeys[] = false !== \strpos($sCurrent, $sKey.' ') ? $sKey :
(0 === \strpos($sType, 'INT') ? '\'0\'' : '\'\'');
}
$sNewKeys = \implode(', ', $aNewKeys);
$sOldKeys = \implode(', ', $aOldKeys);
$this->prepareAndExecute($oPdo, 'INSERT INTO `'.$sTableName.'` ('.$sNewKeys.') SELECT '.$sOldKeys.' FROM `'.$sTableName.'_old`');
$this->prepareAndExecute($oPdo, 'DROP TABLE `'.$sTableName.'_old`');
}
}
@\file_put_contents($sVersionFile, \RainLoop\Providers\Contacts\Classes\Db::Version());
if ($this->oLogger)
{
$this->oLogger->Write('Stop to sync', \MailSo\Log\Enumerations\Type::INFO);
}
}
/**
* @param \RainLoop\Account|\PDO $oAccountOrPdo
* @param string $sSql
* @param array $aParams
*
* @return \PDOStatement|null
*/
private function prepareAndExecute($oAccountOrPdo, $sSql, $aParams = array())
{
if ($this->oLogger)
{
$this->oLogger->Write($sSql, \MailSo\Log\Enumerations\Type::INFO, 'SQLITE');
}
$oPdo = $oAccountOrPdo instanceof \PDO ? $oAccountOrPdo : $this->getPDO($oAccountOrPdo);
$oStmt = $oPdo->prepare($sSql);
foreach ($aParams as $sName => $aValue)
{
$oStmt->bindValue($sName, $aValue[0], $aValue[1]);
}
// $sLogSql = $sSql;
// foreach($aParams as $sName => $aValue)
// {
// $sLogSql = \str_replace($sName, $aValue[1] === \PDO::PARAM_INT ? $aValue[0] : '\''.$aValue[0].'\'', $sLogSql);
// }
//
// if ($this->oLogger)
// {
// $this->oLogger->Write($sLogSql, \MailSo\Log\Enumerations\Type::INFO, 'SQLITE');
// }
$mResult = $oStmt->execute() ? $oStmt : null;
// if ($this->oLogger)
// {
// $this->oLogger->Write('RESULT: '.($mResult ? 'true' : 'false'), \MailSo\Log\Enumerations\Type::INFO, 'SQLITE');
// }
return $mResult;
}
/**
* @param \RainLoop\Account|null $oAccount
* @param bool $bSkipInsert = false
*
* @return int
*/
private function getUserId($oAccount, $bSkipInsert = false)
{
if (!$this->bUseDbPerUser)
{
$oStmt = $this->prepareAndExecute($oAccount,
'SELECT IdUser FROM rlContactsUsers WHERE Email = :Email LIMIT 1',
array(
':Email' => array($oAccount->ParentEmailHelper(), \PDO::PARAM_STR)
));
$mRow = $oStmt->fetch(\PDO::FETCH_ASSOC);
if ($mRow && isset($mRow['IdUser']) && \is_numeric($mRow['IdUser']))
{
return (int) $mRow['IdUser'];
}
if (!$bSkipInsert)
{
$oStmt->closeCursor();
$oStmt = $this->prepareAndExecute($oAccount,
'INSERT INTO rlContactsUsers (Email) VALUES (:Email)',
array(
':Email' => array($oAccount->ParentEmailHelper(), \PDO::PARAM_STR)
));
return $this->getUserId($oAccount, true);
}
throw new \Exception('IdUser=0');
}
return 0;
}
/**
* @param string $sSearch
* @return string
*/
private function convertSearchValue($sSearch)
{
return '%'.$sSearch.'%';
}
private function populateContactFromDB($iUserID, $aItem)
{
$oContact = null;
if (isset($aItem['IdContact']))
{
$oContact = new \RainLoop\Providers\Contacts\Classes\Contact();
$oContact->IdContact = (int) $aItem['IdContact'];
$oContact->IdUser = $iUserID;
$oContact->Type = (int) $aItem['Type'];
$oContact->Frec = (int) $aItem['Frec'];
$oContact->ListName = (string) $aItem['ListName'];
$oContact->Name = (string) $aItem['Name'];
$oContact->Emails = \explode(' ', \trim((string) $aItem['Emails']));
$oContact->ImageHash = (string) $aItem['ImageHash'];
$oContact->ParseData($aItem['Data']);
}
return $oContact;
}
/**
* @param \RainLoop\Account $oAccount
* @param int $iIdContact
*
* @return $oContact|null
*/
public function GetContactById($oAccount, $iIdContact)
{
$oResultContact = null;
$iUserID = $this->getUserId($oAccount);
$oStmt = $this->prepareAndExecute($oAccount,
'SELECT IdContact, Type, Frec, ListName, Name, Emails, ImageHash, Data'.
' FROM rlContactsItems WHERE IdContact = :IdContact AND IdUser = :IdUser LIMIT 1',
array(
':IdContact' => array($iIdContact, \PDO::PARAM_INT),
':IdUser' => array($iUserID, \PDO::PARAM_INT)
));
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
if (\is_array($aFetch) && isset($aFetch[0]) && \is_array($aFetch[0]))
{
$oContact = $this->populateContactFromDB($iUserID, $aFetch[0]);
if ($oContact instanceof \RainLoop\Providers\Contacts\Classes\Contact)
{
$oResultContact = $oContact;
}
}
return $oResultContact;
}
/**
* @param \RainLoop\Account $oAccount
* @param int $iOffset = 0
* @param int $iLimit = 20
* @param string $sSearch = ''
*
* @return array
*/
public function GetContacts($oAccount, $iOffset = 0, $iLimit = 20, $sSearch = '')
{
$iOffset = 0 <= $iOffset ? $iOffset : 0;
$iLimit = 0 < $iLimit ? (int) $iLimit : 0;
$sSearch = \trim($sSearch);
$iUserID = $this->getUserId($oAccount);
$sSql = 'SELECT IdContact, Type, Frec, ListName, Name, Emails, ImageHash, Data'.
' FROM rlContactsItems WHERE IdUser = :IdUser'
;
$aParams = array(
':IdUser' => array($iUserID, \PDO::PARAM_INT),
':limit' => array($iLimit, \PDO::PARAM_INT),
':offset' => array($iOffset, \PDO::PARAM_INT)
);
if (0 < strlen($sSearch))
{
if (\MailSo\Base\Utils::IsAscii($sSearch))
{
$sSql .= ' AND Name LIKE :Search OR Emails LIKE :Search';
$aParams[':Search'] = array($this->convertSearchValue($sSearch), \PDO::PARAM_STR);
}
else
{
$sSql .= ' AND SIMPLESEARCH(Emails, Name, :Search)';
$aParams[':Search'] = array($sSearch, \PDO::PARAM_STR);
}
}
$sSql .= ' ORDER BY ListName ASC LIMIT :limit OFFSET :offset';
$oStmt = $this->prepareAndExecute($oAccount, $sSql, $aParams);
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
$aResult = array();
if (\is_array($aFetch) && 0 < \count($aFetch))
{
foreach ($aFetch as $aItem)
{
$oContact = $this->populateContactFromDB($iUserID, $aItem);
if ($oContact instanceof \RainLoop\Providers\Contacts\Classes\Contact)
{
$aResult[] = $oContact;
}
}
}
unset($aFetch);
return $aResult;
}
/**
* @param \RainLoop\Account $oAccount
*
* @return array
*/
public function GetContactsImageHashes($oAccount)
{
$iUserID = $this->getUserId($oAccount);
$oStmt = $this->prepareAndExecute($oAccount,
'SELECT Emails, ImageHash FROM rlContactsItems WHERE IdUser = :IdUser AND ImageHash <> :ImageHash',
array(
':IdUser' => array($iUserID, \PDO::PARAM_INT),
':ImageHash' => array('', \PDO::PARAM_STR)
));
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
$aResult = array();
if (\is_array($aFetch) && 0 < \count($aFetch))
{
foreach ($aFetch as $aItem)
{
if (!empty($aItem['Emails']) && !empty($aItem['ImageHash']))
{
$aEmails = \explode(' ', $aItem['Emails']);
foreach ($aEmails as $sEmail)
{
$sEmail = \trim($sEmail);
if (0 < strlen($sEmail))
{
$aResult[$sEmail] = $aItem['ImageHash'];
}
}
}
}
}
unset($aFetch);
return $aResult;
}
/**
* @param \RainLoop\Account $oAccount
* @param \RainLoop\Providers\Contacts\Classes\Contact $oContact
*
* @return bool
*/
public function CreateContact($oAccount, &$oContact)
{
$iUserID = $this->getUserId($oAccount);
$oContact->IdUser = $iUserID;
$oStmt = $this->prepareAndExecute($oAccount,
'INSERT INTO rlContactsItems '.
'( IdUser, Type, Frec, ListName, Name, Emails, ImageHash, Data) VALUES '.
'(:IdUser, :Type, 0, :ListName, :Name, :Emails, :ImageHash, :Data)',
array(
':IdUser' => array($oContact->IdUser, \PDO::PARAM_INT),
':Type' => array($oContact->Type, \PDO::PARAM_INT),
':ListName' => array($oContact->GenarateListName(), \PDO::PARAM_STR),
':Name' => array($oContact->Name, \PDO::PARAM_STR),
':Emails' => array($oContact->EmailsAsString(), \PDO::PARAM_STR),
':ImageHash' => array($oContact->ImageHash, \PDO::PARAM_STR),
':Data' => array($oContact->DataAsString(), \PDO::PARAM_STR),
));
if ($oStmt)
{
$iContactID = $this->getPDO($oAccount)->lastInsertId('IdContact');
if (is_numeric($iContactID) && 0 < (int) $iContactID)
{
$oContact->IdContact = (int) $iContactID;
return true;
}
}
throw new \Exception('CreateContact');
}
/**
* @param \RainLoop\Account $oAccount
* @param \RainLoop\Providers\Contacts\Classes\Contact $oContact
*
* @return bool
*/
public function UpdateContact($oAccount, &$oContact)
{
$iUserID = $this->getUserId($oAccount);
$oContact->IdUser = $iUserID;
return !!$this->prepareAndExecute($oAccount,
'UPDATE rlContactsItems SET'.
' Type = :Type, ListName = :ListName, Name = :Name, Emails = :Emails,'.
' ImageHash = :ImageHash, Data = :Data'.
' WHERE IdContact = :IdContact AND IdUser = :IdUser',
array(
':IdContact' => array($oContact->IdContact, \PDO::PARAM_INT),
':IdUser' => array($oContact->IdUser, \PDO::PARAM_INT),
':Type' => array($oContact->Type, \PDO::PARAM_INT),
':ListName' => array($oContact->GenarateListName(), \PDO::PARAM_STR),
':Name' => array($oContact->Name, \PDO::PARAM_STR),
':Emails' => array($oContact->EmailsAsString(), \PDO::PARAM_STR),
':ImageHash' => array($oContact->ImageHash, \PDO::PARAM_STR),
':Data' => array($oContact->DataAsString(), \PDO::PARAM_STR),
));
}
/**
* @param \RainLoop\Account $oAccount
* @param array $aContactIds
*
* @return bool
*/
public function DeleteContacts($oAccount, $aContactIds)
{
$iUserID = $this->getUserId($oAccount);
$aParams = array(
':IdUser' => array($iUserID, \PDO::PARAM_INT),
);
$aInQuery = array();
foreach ($aContactIds as $iIndex => $iId)
{
$aInQuery[] = ':IdContact_'.$iIndex;
$aParams[':IdContact_'.$iIndex] = array($iId, \PDO::PARAM_INT);
}
if (0 === \count($aInQuery))
{
return false;
}
return !!$this->prepareAndExecute($oAccount,
'DELETE FROM rlContactsItems WHERE IdUser = :IdUser AND IdContact IN ('.\implode(', ', $aInQuery).')',
$aParams);
}
/**
* @return bool
*/
public function IsSupported()
{
$aDrivers = \class_exists('PDO') ? \PDO::getAvailableDrivers() : array();
return \is_array($aDrivers) ? \in_array('sqlite', $aDrivers) : false;
}
/**
* @param \RainLoop\Account $oAccount
* @param array $aContactIds
*
* @return bool
*/
public function IncFrec($oAccount, $aContactIds)
{
if (\is_array($aContactIds) && 0 < \count($aContactIds))
{
$iUserID = $this->getUserId($oAccount);
$aParams = array(
':IdUser' => array($iUserID, \PDO::PARAM_INT),
);
$aInQuery = array();
foreach ($aContactIds as $iIndex => $iId)
{
$aInQuery[] = ':IdContact_'.$iIndex;
$aParams[':IdContact_'.$iIndex] = array($iId, \PDO::PARAM_INT);
}
return !!$this->prepareAndExecute($oAccount,
'UPDATE rlContactsItems SET Frec = Frec + 1 WHERE IdUser = :IdUser AND IdContact IN ('.\implode(', ', $aInQuery).')',
$aParams);
}
return false;
}
}

View file

@ -42,6 +42,15 @@ class PersonalAddressBook extends \RainLoop\Providers\AbstractProvider
$this->oDriver->IsSupported();
}
/**
* @return bool
*/
public function IsSharingAllowed()
{
return $this->oDriver instanceof \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface &&
$this->oDriver->IsSharingAllowed();
}
/**
* @return bool
*/
@ -51,6 +60,19 @@ class PersonalAddressBook extends \RainLoop\Providers\AbstractProvider
$this->oDriver->IsSupported();
}
/**
* @param bool $bConsiderShare = true
*/
public function ConsiderShare($bConsiderShare = true)
{
if ($this->oDriver)
{
$this->oDriver->ConsiderShare($bConsiderShare);
}
return $this;
}
/**
* @param \RainLoop\Account $oAccount
* @param \RainLoop\Providers\PersonalAddressBook\Classes\Contact $oContact
@ -78,16 +100,14 @@ class PersonalAddressBook extends \RainLoop\Providers\AbstractProvider
* @param int $iOffset = 0
* @param type $iLimit = 20
* @param string $sSearch = ''
* @param int $iScopeType = \RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_
* @param int $iResultCount = 0
*
* @return array
*/
public function GetContacts($oAccount, $iOffset = 0, $iLimit = 20, $sSearch = '',
$iScopeType = \RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_, &$iResultCount = 0)
public function GetContacts($oAccount, $iOffset = 0, $iLimit = 20, $sSearch = '', &$iResultCount = 0)
{
return $this->IsActive() ? $this->oDriver->GetContacts($oAccount,
$iOffset, $iLimit, $sSearch, $iScopeType, $iResultCount) : array();
$iOffset, $iLimit, $sSearch, $iResultCount) : array();
}
/**

View file

@ -29,11 +29,6 @@ class Contact
*/
public $ScopeType;
/**
* @var string
*/
public $ScopeValue;
/**
* @var int
*/
@ -67,7 +62,6 @@ class Contact
$this->DisplayName = '';
$this->DisplayEmail = '';
$this->ScopeType = \RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_;
$this->ScopeValue = '';
$this->Changed = \time();
$this->IdPropertyFromSearch = 0;
$this->Properties = array();
@ -84,7 +78,6 @@ class Contact
if ($oProperty)
{
$oProperty->ScopeType = $this->ScopeType;
$oProperty->ScopeValue = $this->ScopeValue;
$oProperty->UpdateDependentValues();
if ('' === $sDisplayName && \RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType::FULLNAME === $oProperty->Type &&

View file

@ -21,11 +21,6 @@ class Property
*/
public $ScopeType;
/**
* @var string
*/
public $ScopeValue;
/**
* @var string
*/
@ -39,7 +34,7 @@ class Property
/**
* @var string
*/
public $ValueClear;
public $ValueCustom;
/**
* @var int
@ -57,11 +52,10 @@ class Property
$this->Type = PropertyType::UNKNOWN;
$this->ScopeType = \RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_;
$this->ScopeValue = '';
$this->TypeCustom = '';
$this->Value = '';
$this->ValueClear = '';
$this->ValueCustom = '';
$this->Frec = 0;
}
@ -92,7 +86,7 @@ class Property
{
// trimer
$this->Value = \trim($this->Value);
$this->ValueClear = \trim($this->ValueClear);
$this->ValueCustom = \trim($this->ValueCustom);
$this->TypeCustom = \trim($this->TypeCustom);
if (0 < \strlen($this->Value))
@ -109,7 +103,7 @@ class Property
$sPhone = $this->Value;
$sPhone = \preg_replace('/^[+]+/', '', $sPhone);
$sPhone = \preg_replace('/[^\d]/', '', $sPhone);
$this->ValueClear = $sPhone;
$this->ValueCustom = $sPhone;
}
}
}

View file

@ -5,8 +5,5 @@ namespace RainLoop\Providers\PersonalAddressBook\Enumerations;
class ScopeType
{
const DEFAULT_ = 0;
const AUTO = 1;
const SHARE_ALL = 2;
const SHARE_DOMAIN = 3;
const SHARE_EMAIL = 4;
}

View file

@ -28,16 +28,35 @@ class PdoPersonalAddressBook
*/
private $sPassword;
/**
* @var bool
*/
private $bConsiderShare;
public function __construct($sDsn, $sUser = '', $sPassword = '', $sDsnType = 'mysql')
{
$this->sDsn = $sDsn;
$this->sUser = $sUser;
$this->sPassword = $sPassword;
$this->sDsnType = $sDsnType;
$this->bConsiderShare = true;
$this->bExplain = false;
}
/**
* @param bool $bConsiderShare
*
* @return \RainLoop\Providers\PersonalAddressBook\PdoPersonalAddressBook
*/
public function ConsiderShare($bConsiderShare = true)
{
$this->bConsiderShare = !!$bConsiderShare;
return $this;
}
/**
* @return bool
*/
@ -47,6 +66,22 @@ class PdoPersonalAddressBook
return \is_array($aDrivers) ? \in_array($this->sDsnType, $aDrivers) : false;
}
/**
* @return bool
*/
public function IsConsiderShare()
{
return $this->bConsiderShare;
}
/**
* @return bool
*/
public function IsSharingAllowed()
{
return $this->IsConsiderShare() && $this->IsSupported();
}
/**
* @param \RainLoop\Account $oAccount
* @param \RainLoop\Providers\PersonalAddressBook\Classes\Contact $oContact
@ -62,42 +97,14 @@ class PdoPersonalAddressBook
$bUpdate = 0 < $iIdContact;
$oContact->UpdateDependentValues();
$oContact->Changed = \time();
if (\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::AUTO !== $oContact->ScopeType)
if (!$this->bConsiderShare)
{
$aEmail = $oContact->GetEmails();
if (0 < \count($aEmail))
{
$aEmail = \array_map(function ($sValue) {
return \strtolower(\trim($sValue));
}, $aEmail);
$aEmail = \array_filter($aEmail, function ($sValue) {
return !empty($sValue);
});
if (0 < \count($aEmail))
{
$self = $this;
$aEmail = \array_map(function ($sValue) use ($self) {
return $self->quoteValue($sValue);
}, $aEmail);
// clear autocreated contacts
$this->prepareAndExecute(
'DELETE FROM rainloop_pab_contacts WHERE id_user = :id_user AND scope_type = :scope_type AND display_email IN ('.\implode(',', $aEmail).')',
array(
':scope_type' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::AUTO, \PDO::PARAM_INT),
':id_user' => array($iUserID, \PDO::PARAM_INT)
)
);
}
}
$oContact->ScopeType = \RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_;
}
$oContact->UpdateDependentValues();
$oContact->Changed = \time();
try
{
if ($this->isTransactionSupported())
@ -111,7 +118,7 @@ class PdoPersonalAddressBook
$aFreq = $this->getContactFreq($iUserID, $iIdContact);
$sSql = 'UPDATE rainloop_pab_contacts SET display = :display, display_name = :display_name, display_email = :display_email, '.
'scope_type = :scope_type, scope_value = :scope_value, changed = :changed WHERE id_user = :id_user AND id_contact = :id_contact';
'scope_type = :scope_type, changed = :changed WHERE id_user = :id_user AND id_contact = :id_contact';
$this->prepareAndExecute($sSql,
array(
@ -121,7 +128,6 @@ class PdoPersonalAddressBook
':display_name' => array($oContact->DisplayName, \PDO::PARAM_STR),
':display_email' => array($oContact->DisplayEmail, \PDO::PARAM_STR),
':scope_type' => array($oContact->ScopeType, \PDO::PARAM_INT),
':scope_value' => array($oContact->ScopeValue, \PDO::PARAM_STR),
':changed' => array($oContact->Changed, \PDO::PARAM_INT),
)
);
@ -138,8 +144,8 @@ class PdoPersonalAddressBook
else
{
$sSql = 'INSERT INTO rainloop_pab_contacts '.
'( id_user, display, display_name, display_email, scope_type, scope_value, changed) VALUES '.
'(:id_user, :display, :display_name, :display_email, :scope_type, :scope_value, :changed)';
'( id_user, display, display_name, display_email, scope_type, changed) VALUES '.
'(:id_user, :display, :display_name, :display_email, :scope_type, :changed)';
$this->prepareAndExecute($sSql,
array(
@ -148,7 +154,6 @@ class PdoPersonalAddressBook
':display_name' => array($oContact->DisplayName, \PDO::PARAM_STR),
':display_email' => array($oContact->DisplayEmail, \PDO::PARAM_STR),
':scope_type' => array($oContact->ScopeType, \PDO::PARAM_INT),
':scope_value' => array($oContact->ScopeValue, \PDO::PARAM_STR),
':changed' => array($oContact->Changed, \PDO::PARAM_INT)
)
);
@ -176,18 +181,17 @@ class PdoPersonalAddressBook
':id_contact' => array($iIdContact, \PDO::PARAM_INT),
':id_user' => array($iUserID, \PDO::PARAM_INT),
':scope_type' => array($oContact->ScopeType, \PDO::PARAM_INT),
':scope_value' => array($oContact->ScopeValue, \PDO::PARAM_STR),
':prop_type' => array($oProp->Type, \PDO::PARAM_INT),
':prop_type_custom' => array($oProp->TypeCustom, \PDO::PARAM_STR),
':prop_value' => array($oProp->Value, \PDO::PARAM_STR),
':prop_value_custom' => array($oProp->ValueClear, \PDO::PARAM_STR),
':prop_value_custom' => array($oProp->ValueCustom, \PDO::PARAM_STR),
':prop_frec' => array($iFreq, \PDO::PARAM_INT),
);
}
$sSql = 'INSERT INTO rainloop_pab_properties '.
'( id_contact, id_user, prop_type, prop_type_custom, prop_value, prop_value_custom, scope_type, scope_value, prop_frec) VALUES '.
'(:id_contact, :id_user, :prop_type, :prop_type_custom, :prop_value, :prop_value_custom, :scope_type, :scope_value, :prop_frec)';
'( id_contact, id_user, prop_type, prop_type_custom, prop_value, prop_value_custom, scope_type, prop_frec) VALUES '.
'(:id_contact, :id_user, :prop_type, :prop_type_custom, :prop_value, :prop_value_custom, :scope_type, :prop_frec)';
$this->prepareAndExecute($sSql, $aParams, true);
}
@ -275,13 +279,11 @@ class PdoPersonalAddressBook
* @param int $iOffset = 0
* @param int $iLimit = 20
* @param string $sSearch = ''
* @param bool $iScopeType = \RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_
* @param int $iResultCount = 0
*
* @return array
*/
public function GetContacts($oAccount, $iOffset = 0, $iLimit = 20, $sSearch = '',
$iScopeType = \RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_, &$iResultCount = 0)
public function GetContacts($oAccount, $iOffset = 0, $iLimit = 20, $sSearch = '', &$iResultCount = 0)
{
$this->Sync();
@ -289,10 +291,7 @@ class PdoPersonalAddressBook
$iLimit = 0 < $iLimit ? (int) $iLimit : 20;
$sSearch = \trim($sSearch);
$sEmail = $oAccount->ParentEmailHelper();
$sDomain = \MailSo\Base\Utils::GetDomainFromEmail($sEmail);
$iUserID = $this->getUserId($sEmail);
$iUserID = $this->getUserId($oAccount->ParentEmailHelper());
$iCount = 0;
$aSearchIds = array();
@ -302,22 +301,27 @@ class PdoPersonalAddressBook
{
$sSql = 'SELECT id_user, id_prop, id_contact FROM rainloop_pab_properties '.
'WHERE ('.
'(id_user = :id_user)'.
' OR (scope_type = :scope_type_share_all)'.
' OR (scope_type = :scope_type_share_domain AND scope_value = :scope_value_domain)'.
' OR (scope_type = :scope_type_share_email AND scope_value = :scope_value_email)'.
') AND prop_value LIKE :search ESCAPE \'=\' GROUP BY id_contact, id_prop';
'id_user = :id_user'.
($this->bConsiderShare ? ' OR scope_type = :scope_type_share_all' : '').
') AND (prop_value LIKE :search ESCAPE \'=\' OR ('.
'prop_type IN ('.\implode(',', array(
PropertyType::PHONE_PERSONAL, PropertyType::PHONE_BUSSINES, PropertyType::PHONE_OTHER,
PropertyType::MOBILE_PERSONAL, PropertyType::MOBILE_BUSSINES, PropertyType::MOBILE_OTHER,
PropertyType::FAX_PERSONAL, PropertyType::FAX_BUSSINES, PropertyType::FAX_OTHER
)).') AND prop_value_custom LIKE :search_custom_phone'.
')) GROUP BY id_contact, id_prop';
$aParams = array(
':id_user' => array($iUserID, \PDO::PARAM_INT),
':scope_type_share_all' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_ALL, \PDO::PARAM_INT),
':scope_type_share_domain' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_DOMAIN, \PDO::PARAM_INT),
':scope_type_share_email' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_EMAIL, \PDO::PARAM_INT),
':scope_value_domain' => array($sDomain, \PDO::PARAM_STR),
':scope_value_email' => array($sEmail, \PDO::PARAM_STR),
':search' => array($this->specialConvertSearchValue($sSearch, '='), \PDO::PARAM_STR)
':search' => array($this->specialConvertSearchValue($sSearch, '='), \PDO::PARAM_STR),
':search_custom_phone' => array($this->specialConvertSearchValueCustomPhone($sSearch), \PDO::PARAM_STR)
);
if ($this->bConsiderShare)
{
$aParams[':scope_type_share_all'] = array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_ALL, \PDO::PARAM_INT);
}
$oStmt = $this->prepareAndExecute($sSql, $aParams);
if ($oStmt)
{
@ -341,23 +345,19 @@ class PdoPersonalAddressBook
else
{
$sSql = 'SELECT COUNT(DISTINCT id_contact) as contact_count FROM rainloop_pab_properties '.
'WHERE ('.
'(id_user = :id_user)'.
' OR (scope_type = :scope_type_share_all)'.
' OR (scope_type = :scope_type_share_domain AND scope_value = :scope_value_domain)'.
' OR (scope_type = :scope_type_share_email AND scope_value = :scope_value_email)'.
')'
'WHERE id_user = :id_user'.
($this->bConsiderShare ? ' OR scope_type = :scope_type_share_all' : '')
;
$aParams = array(
':id_user' => array($iUserID, \PDO::PARAM_INT),
':scope_type_share_all' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_ALL, \PDO::PARAM_INT),
':scope_type_share_domain' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_DOMAIN, \PDO::PARAM_INT),
':scope_type_share_email' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_EMAIL, \PDO::PARAM_INT),
':scope_value_domain' => array($sDomain, \PDO::PARAM_STR),
':scope_value_email' => array($sEmail, \PDO::PARAM_STR)
':id_user' => array($iUserID, \PDO::PARAM_INT)
);
if ($this->bConsiderShare)
{
$aParams[':scope_type_share_all'] = array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_ALL, \PDO::PARAM_INT);
}
$oStmt = $this->prepareAndExecute($sSql, $aParams);
if ($oStmt)
{
@ -374,23 +374,19 @@ class PdoPersonalAddressBook
if (0 < $iCount)
{
$sSql = 'SELECT * FROM rainloop_pab_contacts '.
'WHERE ('.
'(id_user = :id_user)'.
' OR (scope_type = :scope_type_share_all)'.
' OR (scope_type = :scope_type_share_domain AND scope_value = :scope_value_domain)'.
' OR (scope_type = :scope_type_share_email AND scope_value = :scope_value_email)'.
')'
'WHERE id_user = :id_user'.
($this->bConsiderShare ? ' OR scope_type = :scope_type_share_all' : '')
;
$aParams = array(
':id_user' => array($iUserID, \PDO::PARAM_INT),
':scope_type_share_all' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_ALL, \PDO::PARAM_INT),
':scope_type_share_domain' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_DOMAIN, \PDO::PARAM_INT),
':scope_type_share_email' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_EMAIL, \PDO::PARAM_INT),
':scope_value_domain' => array($sDomain, \PDO::PARAM_STR),
':scope_value_email' => array($sEmail, \PDO::PARAM_STR)
':id_user' => array($iUserID, \PDO::PARAM_INT)
);
if ($this->bConsiderShare)
{
$aParams[':scope_type_share_all'] = array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_ALL, \PDO::PARAM_INT);
}
if (0 < \count($aSearchIds))
{
$sSql .= ' AND id_contact IN ('.implode(',', $aSearchIds).')';
@ -423,7 +419,6 @@ class PdoPersonalAddressBook
$oContact->DisplayEmail = isset($aItem['display_email']) ? (string) $aItem['display_email'] : '';
$oContact->ScopeType = isset($aItem['scope_type']) ? (int) $aItem['scope_type'] :
\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_;
$oContact->ScopeValue = isset($aItem['scope_value']) ? (string) $aItem['scope_value'] : '';
$oContact->Changed = isset($aItem['changed']) ? (int) $aItem['changed'] : 0;
$oContact->ReadOnly = $iUserID !== (isset($aItem['id_user']) ? (int) $aItem['id_user'] : 0);
@ -460,11 +455,10 @@ class PdoPersonalAddressBook
$oProperty->IdProperty = (int) $aItem['id_prop'];
$oProperty->ScopeType = isset($aItem['scope_type']) ? (int) $aItem['scope_type'] :
\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_;
$oProperty->ScopeValue = isset($aItem['scope_value']) ? (string) $aItem['scope_value'] : '';
$oProperty->Type = (int) $aItem['prop_type'];
$oProperty->TypeCustom = isset($aItem['prop_type_custom']) ? (string) $aItem['prop_type_custom'] : '';
$oProperty->Value = (string) $aItem['prop_value'];
$oProperty->ValueClear = isset($aItem['prop_value_clear']) ? (string) $aItem['prop_value_clear'] : '';
$oProperty->ValueCustom = isset($aItem['prop_value_custom']) ? (string) $aItem['prop_value_custom'] : '';
$oProperty->Frec = isset($aItem['prop_frec']) ? (int) $aItem['prop_frec'] : 0;
$aContacts[$iId]->Properties[] = $oProperty;
@ -508,34 +502,29 @@ class PdoPersonalAddressBook
$this->Sync();
$sEmail = $oAccount->ParentEmailHelper();
$sDomain = \MailSo\Base\Utils::GetDomainFromEmail($sEmail);
$iUserID = $this->getUserId($sEmail);
$iUserID = $this->getUserId($oAccount->ParentEmailHelper());
$sTypes = implode(',', array(
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER, PropertyType::FULLNAME
));
$sSql = 'SELECT id_contact, id_prop, prop_type, prop_value FROM rainloop_pab_properties '.
'WHERE ('.
'(id_user = :id_user)'.
' OR (scope_type = :scope_type_share_all)'.
' OR (scope_type = :scope_type_share_domain AND scope_value = :scope_value_domain)'.
' OR (scope_type = :scope_type_share_email AND scope_value = :scope_value_email)'.
'id_user = :id_user'.
($this->bConsiderShare ? ' OR scope_type = :scope_type_share_all' : '').
') AND prop_type IN ('.$sTypes.') AND prop_value LIKE :search ESCAPE \'=\'';
$aParams = array(
':id_user' => array($iUserID, \PDO::PARAM_INT),
':limit' => array($iLimit, \PDO::PARAM_INT),
':scope_type_share_all' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_ALL, \PDO::PARAM_INT),
':scope_type_share_domain' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_DOMAIN, \PDO::PARAM_INT),
':scope_type_share_email' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_EMAIL, \PDO::PARAM_INT),
':scope_value_domain' => array($sDomain, \PDO::PARAM_STR),
':scope_value_email' => array($sEmail, \PDO::PARAM_STR),
':search' => array($this->specialConvertSearchValue($sSearch, '='), \PDO::PARAM_STR)
);
if ($this->bConsiderShare)
{
$aParams[':scope_type_share_all'] = array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_ALL, \PDO::PARAM_INT);
}
$sSql .= ' ORDER BY prop_frec DESC';
$sSql .= ' LIMIT :limit';
@ -765,7 +754,7 @@ class PdoPersonalAddressBook
$oContact = new \RainLoop\Providers\PersonalAddressBook\Classes\Contact();
foreach ($aEmailsToCreate as $oEmail)
{
$oContact->ScopeType = \RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::AUTO;
$oContact->ScopeType = \RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_;
if ('' !== \trim($oEmail->GetEmail()))
{
@ -1042,27 +1031,15 @@ SQLITEINITIAL;
{
case 'mysql':
return $this->dataBaseUpgrade($this->sDsnType.'-pab-version', array(
1 => $this->getInitialTablesArray($this->sDsnType),
2 => array(
'ALTER TABLE rainloop_pab_contacts ADD scope_value varchar(128) NOT NULL DEFAULT \'\' AFTER scope_type',
'ALTER TABLE rainloop_pab_properties ADD scope_value varchar(128) NOT NULL DEFAULT \'\' AFTER scope_type'
)
1 => $this->getInitialTablesArray($this->sDsnType)
));
case 'pgsql':
return $this->dataBaseUpgrade($this->sDsnType.'-pab-version', array(
1 => $this->getInitialTablesArray($this->sDsnType),
2 => array(
'ALTER TABLE rainloop_pab_contacts ADD scope_value varchar(128) NOT NULL DEFAULT \'\'',
'ALTER TABLE rainloop_pab_properties ADD scope_value varchar(128) NOT NULL DEFAULT \'\''
)
1 => $this->getInitialTablesArray($this->sDsnType)
));
case 'sqlite':
return $this->dataBaseUpgrade($this->sDsnType.'-pab-version', array(
1 => $this->getInitialTablesArray($this->sDsnType),
2 => array(
'ALTER TABLE rainloop_pab_contacts ADD scope_value text NOT NULL default \'\'',
'ALTER TABLE rainloop_pab_properties ADD scope_value text NOT NULL default \'\''
)
1 => $this->getInitialTablesArray($this->sDsnType)
));
}
@ -1109,6 +1086,7 @@ SQLITEINITIAL;
/**
* @param string $sSearch
* @param string $sEscapeSign = '='
*
* @return string
*/
@ -1118,6 +1096,16 @@ SQLITEINITIAL;
array($sEscapeSign.$sEscapeSign, $sEscapeSign.'_', $sEscapeSign.'%'), $sSearch).'%';
}
/**
* @param string $sSearch
*
* @return string
*/
private function specialConvertSearchValueCustomPhone($sSearch)
{
return '%'.\preg_replace('/[^\d]/', '', $sSearch).'%';
}
/**
* @return array
*/

View file

@ -38,13 +38,11 @@ interface PersonalAddressBookInterface
* @param int $iOffset = 0
* @param int $iLimit = 20
* @param string $sSearch = ''
* @param bool $iScopeType = \RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_
* @param int $iResultCount = 0
*
* @return array
*/
public function GetContacts($oAccount, $iOffset = 0, $iLimit = 20, $sSearch = '',
$iScopeType = \RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_, &$iResultCount = 0);
public function GetContacts($oAccount, $iOffset = 0, $iLimit = 20, $sSearch = '', &$iResultCount = 0);
/**
* @param \RainLoop\Account $oAccount