The final commit personal address books branches before merging

This commit is contained in:
RainLoop Team 2013-12-07 01:50:19 +04:00
parent 43f094220c
commit 867dcc8f7e
44 changed files with 2163 additions and 1147 deletions

View file

@ -1090,6 +1090,11 @@ class Utils
*/
public static function Utf8Clear($sUtfString, $sReplaceOn = '')
{
if ('' === $sUtfString)
{
return $sUtfString;
}
$sUtfString = @\iconv('UTF-8', 'UTF-8//IGNORE', $sUtfString);
$sUtfString = \preg_replace(

View file

@ -76,15 +76,10 @@ class Actions
*/
private $oLoginProvider;
/**
* @var \RainLoop\Providers\Contacts
*/
private $oContactsProvider;
/**
* @var \RainLoop\Providers\PersonalAddressBook
*/
private $oPersonalAddressBook;
private $oPersonalAddressBookProvider;
/**
* @var \RainLoop\Providers\Suggestions
@ -126,8 +121,7 @@ class Actions
$this->oSettingsProvider = null;
$this->oDomainProvider = null;
$this->oLoginProvider = null;
$this->oContactsProvider = null;
$this->oPersonalAddressBook = null;
$this->oPersonalAddressBookProvider = null;
$this->oSuggestionsProvider = null;
$this->oChangePasswordProvider = null;
@ -203,7 +197,6 @@ class Actions
{
$oResult = null;
$this->Plugins()->RunHook('main.fabrica', array($sName, &$oResult), false);
$this->Plugins()->RunHook('main.fabrica-account', array($sName, &$oResult, &$oAccount), false);
if (null === $oResult)
{
@ -230,14 +223,8 @@ class Actions
// \RainLoop\Providers\Domain\DomainAdminInterface
$oResult = new \RainLoop\Providers\Domain\DefaultDomain(APP_PRIVATE_DATA.'domains');
break;
case 'contacts':
// \RainLoop\Providers\Contacts\ContactsInterface
$oResult = new \RainLoop\Providers\Contacts\DefaultContacts($this->Logger());
break;
case 'personal-address-book':
// \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface
$oResult = new \RainLoop\Providers\PersonalAddressBook\MySqlPersonalAddressBook();
$oResult->SetLogger($this->Logger());
// \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface
break;
case 'suggestions':
// \RainLoop\Providers\Suggestions\SuggestionsInterface
@ -542,50 +529,36 @@ class Actions
}
/**
* @return \RainLoop\Providers\Contacts
*/
public function ContactsProvider()
{
if (null === $this->oContactsProvider)
{
$this->oContactsProvider = new \RainLoop\Providers\Contacts(
$this->Config()->Get('labs', 'allow_contacts', true) ?
$this->fabrica('contacts') : null);
}
return $this->oContactsProvider;
}
/**
* @return \RainLoop\Providers\Contacts
* @return \RainLoop\Providers\PersonalAddressBook
*/
public function PersonalAddressBookProvider($oAccount = null)
{
if (null === $this->oPersonalAddressBook)
if (null === $this->oPersonalAddressBookProvider)
{
$this->oPersonalAddressBook = new \RainLoop\Providers\PersonalAddressBook(
$this->Config()->Get('labs', 'allow_contacts', true) ?
$this->fabrica('personal-address-book', $oAccount) : null);
$this->oPersonalAddressBookProvider = new \RainLoop\Providers\PersonalAddressBook(
$this->fabrica('personal-address-book', $oAccount));
$sPabVersion = $this->oPersonalAddressBookProvider->Version();
$sVersion = (string) $this->StorageProvider()->Get(null,
\RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY, 'PersonalAddressBookVersion', '');
if ($sVersion !== APP_VERSION && $this->oPersonalAddressBook->IsActive())
if ($sVersion !== $sPabVersion &&
$this->oPersonalAddressBookProvider->IsActive())
{
if ($this->oPersonalAddressBook->SynchronizeStorage())
if ($this->oPersonalAddressBookProvider->SynchronizeStorage())
{
$this->StorageProvider()->Put(null, \RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY,
'PersonalAddressBookVersion', APP_VERSION);
'PersonalAddressBookVersion', $sPabVersion);
}
}
}
if ($oAccount)
{
$this->oPersonalAddressBook->SetAccount($oAccount);
$this->oPersonalAddressBookProvider->SetAccount($oAccount);
}
return $this->oPersonalAddressBook;
return $this->oPersonalAddressBookProvider;
}
/**
@ -922,9 +895,8 @@ class Actions
'AllowThemes' => (bool) $oConfig->Get('webmail', 'allow_themes', true),
'AllowCustomTheme' => (bool) $oConfig->Get('webmail', 'allow_custom_theme', true),
'SuggestionsLimit' => (int) $oConfig->Get('labs', 'suggestions_limit', 50),
'AllowChangePassword' => false,
'ContactsIsSupported' => (bool) $this->ContactsProvider()->IsSupported(),
'ContactsIsAllowed' => (bool) $this->ContactsProvider()->IsActive(),
'ChangePasswordIsAllowed' => false,
'ContactsIsAllowed' => false,
'JsHash' => \md5(\RainLoop\Utils::GetConnectionToken()),
'UseImapThread' => (bool) $oConfig->Get('labs', 'use_imap_thread', false),
'UseImapSubscribe' => (bool) $oConfig->Get('labs', 'use_imap_list_subscribe', true),
@ -949,7 +921,8 @@ class Actions
$aResult['IncLogin'] = $oAccount->IncLogin();
$aResult['OutLogin'] = $oAccount->OutLogin();
$aResult['AccountHash'] = $oAccount->Hash();
$aResult['AllowChangePassword'] = $this->ChangePasswordProvider()->PasswordChangePossibility($oAccount);
$aResult['ChangePasswordIsAllowed'] = $this->ChangePasswordProvider()->PasswordChangePossibility($oAccount);
$aResult['ContactsIsAllowed'] = $this->PersonalAddressBookProvider($oAccount)->IsActive();
$oSettings = $this->SettingsProvider()->Load($oAccount);
}
@ -3953,7 +3926,7 @@ class Actions
$aTo =& $oToCollection->GetAsArray();
foreach ($aTo as /* @var $oEmail \MailSo\Mime\Email */ $oEmail)
{
$aArrayToFrec[$oEmail->GetEmail()] = $oEmail->GetEmail();
$aArrayToFrec[$oEmail->GetEmail()] = $oEmail->ToString();
}
}
@ -3991,30 +3964,27 @@ class Actions
public function DoContacts()
{
$oAccount = $this->getAccountFromToken();
$sSearch = \trim($this->GetActionParam('Search', ''));
$iOffset = (int) $this->GetActionParam('Offset', 0);
$iLimit = (int) $this->GetActionParam('Limit', 20);
$iOffset = 0 > $iOffset ? 0 : $iOffset;
$iLimit = 0 > $iLimit ? 20 : $iLimit;
$bMore = false;
$mResult = false;
if ($this->ContactsProvider()->IsActive())
if ($this->PersonalAddressBookProvider($oAccount)->IsActive())
{
$mResult = $this->ContactsProvider()->GetContacts($oAccount, 0, RL_CONTACTS_MAX + 1, $sSearch);
if (is_array($mResult))
{
$bMore = RL_CONTACTS_MAX < \count($mResult);
if ($bMore)
{
$mResult = \array_slice($mResult, 0, RL_CONTACTS_MAX);
}
}
$mResult = $this->PersonalAddressBookProvider($oAccount)->GetContacts($oAccount,
$iOffset, $iLimit, $sSearch, false);
}
return $this->DefaultResponse(__FUNCTION__, array(
'Limit' => RL_CONTACTS_MAX,
'More' => $bMore,
'Offset' => $iOffset,
'Limit' => $iLimit,
'Search' => $sSearch,
'List' => $mResult
));
}
/**
* @return array
*/
@ -4029,9 +3999,9 @@ class Actions
});
$bResult = false;
if ($this->ContactsProvider()->IsActive())
if (0 < \count($aFilteredUids) && $this->PersonalAddressBookProvider($oAccount)->IsActive())
{
$bResult = $this->ContactsProvider()->DeleteContacts($oAccount, $aFilteredUids);
$bResult = $this->PersonalAddressBookProvider($oAccount)->DeleteContacts($oAccount, $aFilteredUids);
}
return $this->DefaultResponse(__FUNCTION__, $bResult);
@ -4042,77 +4012,45 @@ class Actions
*/
public function DoContactSave()
{
sleep(1);
$oAccount = $this->getAccountFromToken();
$bResult = false;
$sResultID = '';
$oPab = $this->PersonalAddressBookProvider($oAccount);
$sRequestUid = \trim($this->GetActionParam('RequestUid', ''));
if ($this->ContactsProvider()->IsActive() && 0 < \strlen($sRequestUid))
if ($oPab && $oPab->IsActive() && 0 < \strlen($sRequestUid))
{
$sUid = \trim($this->GetActionParam('Uid', ''));
$sName = \trim($this->GetActionParam('Name', ''));
$sEmail = \trim($this->GetActionParam('Email', ''));
$sImageData = \trim($this->GetActionParam('ImageData', ''));
$oContact = null;
$oContact = new \RainLoop\Providers\PersonalAddressBook\Classes\Contact();
if (0 < \strlen($sUid))
{
if (\is_numeric($sUid))
{
$oContact = $this->ContactsProvider()->GetContactById($oAccount, (int) $sUid);
}
}
else
{
$oContact = new \RainLoop\Providers\Contacts\Classes\Contact();
$oContact->IdContact = $sUid;
}
if ($oContact)
$aProperties = $this->GetActionParam('Properties', array());
if (\is_array($aProperties))
{
$oContact->Name = $sName;
$oContact->Emails = array($sEmail);
if (0 < \strlen($sImageData) && 'data:image/' === substr($sImageData, 0, 11))
foreach ($aProperties as $aItem)
{
$oContact->ImageHash = \md5($sImageData);
}
if (0 < $oContact->IdContact)
{
$bResult = $this->ContactsProvider()->UpdateContact($oAccount, $oContact);
}
else
{
$bResult = $this->ContactsProvider()->CreateContact($oAccount, $oContact);
}
if ($bResult && 0 < $oContact->IdContact)
{
$sResultID = $oContact->IdContact;
$aMatches = array();
if ($bResult && $oContact && 0 < $oContact->IdContact && 0 < \strlen($oContact->ImageHash) &&
0 < \strlen($sImageData) &&
\preg_match('/^data:(image\/(jpeg|jpg|png|bmp));base64,(.+)$/i', $sImageData, $aMatches) &&
!empty($aMatches[1]) && !empty($aMatches[3]))
if ($aItem && isset($aItem[0], $aItem[1]) &&
\is_numeric($aItem[0]))
{
$this->StorageProvider()->Put($oAccount,
\RainLoop\Providers\Storage\Enumerations\StorageType::USER,
'contacts/'.$oContact->ImageHash, $aMatches[1].'|||'.$aMatches[3]);
$oProp = new \RainLoop\Providers\PersonalAddressBook\Classes\Property();
$oProp->Type = (int) $aItem[0];
$oProp->Value = $aItem[1];
$oContact->Properties[] = $oProp;
}
}
else
{
$bResult = false;
}
}
$bResult = $oPab->ContactSave($oAccount, $oContact);
}
return $this->DefaultResponse(__FUNCTION__, array(
'RequestUid' => $sRequestUid,
'ResultID' => $sResultID,
'ResultID' => $bResult ? $oContact->IdContact : '',
'Result' => $bResult
));
}
@ -4133,73 +4071,7 @@ class Actions
$aResult = $oPab->GetSuggestions($oAccount, $sQuery);
}
return $this->DefaultResponse(__FUNCTION__, array(
'More' => false,
'List' => $aResult
));
}
/**
* @return array
*/
public function DoSuggestionsDep()
{
$oAccount = $this->getAccountFromToken();
$sQuery = \trim($this->GetActionParam('Query', ''));
$iPage = (int) $this->GetActionParam('Page', 0);
$bMore = false;
$aResult = array();
if (0 < \strlen($sQuery) && 0 < $iPage && $this->ContactsProvider()->IsActive())
{
$mResult = $this->ContactsProvider()->GetContacts($oAccount, ($iPage - 1) * RL_CONTACTS_PER_PAGE, RL_CONTACTS_PER_PAGE + 1, $sQuery);
if (\is_array($mResult) && 0 < \count($mResult))
{
$bMore = RL_CONTACTS_PER_PAGE < \count($mResult);
if ($bMore)
{
$mResult = \array_slice($mResult, 0, RL_CONTACTS_PER_PAGE);
}
foreach ($mResult as $oItem)
{
/* @var $oItem \RainLoop\Providers\Contacts\Classes\Contact */
$aEmails = $oItem->Emails;
if (0 < \count($aEmails))
{
foreach ($aEmails as $sEmail)
{
if (0 < \strlen($sEmail))
{
$aResult[] = array($sEmail, $oItem->Name);
}
}
}
}
}
}
return $this->DefaultResponse(__FUNCTION__, array(
'More' => $bMore,
'List' => $aResult
));
// $oAccount = $this->getAccountFromToken();
//
// $aResult = array();
// $sQuery = \trim($this->GetActionParam('Query', ''));
// if (0 < \strlen($sQuery) && $oAccount)
// {
// $aResult = $this->SuggestionsProvider()->Process($oAccount, $sQuery);
//
// if (0 === count($aResult) && false !== \strpos(strtolower($oAccount->Email()), \strtolower($sQuery)))
// {
// $aResult[] = array($oAccount->Email(), $oAccount->Name());
// }
// }
//
// return $this->DefaultResponse(__FUNCTION__, $aResult);
return $this->DefaultResponse(__FUNCTION__, $aResult);
}
/**
@ -4207,19 +4079,8 @@ class Actions
*/
public function DoEmailsPicsHashes()
{
$oAccount = $this->getAccountFromToken();
$aResult = array();
if ($this->ContactsProvider()->IsActive())
{
$mResult = $this->ContactsProvider()->GetContactsImageHashes($oAccount);
if (\is_array($mResult) && 0 < \count($mResult))
{
$aResult = $mResult;
}
}
return $this->DefaultResponse(__FUNCTION__, $aResult);
// $oAccount = $this->getAccountFromToken();
return $this->DefaultResponse(__FUNCTION__, array());
}
/**
@ -5681,7 +5542,7 @@ class Actions
if ($oAttachment)
{
$sContentLocation = $oAttachment->ContentLocation();
if ($sContentLocation && 0 < strlen($sContentLocation))
if ($sContentLocation && 0 < \strlen($sContentLocation))
{
$aContentLocationUrls[] = $oAttachment->ContentLocation();
}
@ -5741,6 +5602,25 @@ class Actions
'Emails' => $mResponse->Emails
));
}
else if ('RainLoop\Providers\PersonalAddressBook\Classes\Contact' === $sClassName)
{
$mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array(
/* @var $mResponse \RainLoop\Providers\PersonalAddressBook\Classes\Contact */
'IdContact' => $mResponse->IdContact,
'Display' => \MailSo\Base\Utils::Utf8Clear($mResponse->Display),
'Properties' => $this->responseObject($mResponse->Properties, $sParent, $aParameters)
));
}
else if ('RainLoop\Providers\PersonalAddressBook\Classes\Property' === $sClassName)
{
$mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array(
/* @var $mResponse \RainLoop\Providers\PersonalAddressBook\Classes\Property */
'Type' => $mResponse->Type,
'TypeCustom' => $mResponse->TypeCustom,
'Value' => \MailSo\Base\Utils::Utf8Clear($mResponse->Value),
'ValueClear' => \MailSo\Base\Utils::Utf8Clear($mResponse->ValueClear)
));
}
else if ('MailSo\Mail\Attachment' === $sClassName)
{
$oAccount = $this->getAccountFromToken(false);

View file

@ -4,6 +4,11 @@ namespace RainLoop\Common;
abstract class PdoAbstract
{
/**
* @var \PDO
*/
protected $oPDO = null;
/**
* @var \MailSo\Log\Logger
*/
@ -35,8 +40,7 @@ abstract class PdoAbstract
*/
protected function getPdoAccessData()
{
$aResult = array('mysql', 'mysql:host=127.0.0.1;port=3306;dbname=rainloop', 'root', '');
return $aResult;
return array('', '', '', '');
}
/**
@ -46,10 +50,9 @@ abstract class PdoAbstract
*/
protected function getPDO()
{
static $aPdoCache = null;
if ($aPdoCache)
if ($this->oPDO)
{
return $aPdoCache;
return $this->oPDO;
}
if (!\class_exists('PDO'))
@ -57,7 +60,6 @@ abstract class PdoAbstract
throw new \Exception('Class PDO does not exist');
}
// TODO
$sType = $sDsn = $sDbLogin = $sDbPassword = '';
list($sType, $sDsn, $sDbLogin, $sDbPassword) = $this->getPdoAccessData();
$this->sDbType = $sType;
@ -83,7 +85,7 @@ abstract class PdoAbstract
if ($oPdo)
{
$aPdoCache = $oPdo;
$this->oPDO = $oPdo;
}
else
{

View file

@ -212,7 +212,6 @@ Enables caching in the system'),
'in_iframe' => array(false),
'custom_login_link' => array(''),
'custom_logout_link' => array(''),
'allow_contacts' => array(true),
'allow_external_login' => array(false),
'allow_admin_panel' => array(true),
'fast_cache_memcache_host' => array('127.0.0.1'),

View file

@ -23,6 +23,15 @@ class PersonalAddressBook extends \RainLoop\Providers\AbstractProvider
}
}
/**
* @return string
*/
public function Version()
{
return $this->oDriver instanceof \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface ?
$this->oDriver->Version() : 'null';
}
/**
* @return bool
*/
@ -33,12 +42,66 @@ class PersonalAddressBook extends \RainLoop\Providers\AbstractProvider
}
/**
* @param \RainLoop\Account $oAccount
* @param \RainLoop\Providers\PersonalAddressBook\Classes\Contact $oContact
*
* @return bool
*/
public function IsSupported()
public function ContactSave($oAccount, &$oContact)
{
return $this->oDriver instanceof \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface &&
$this->oDriver->IsSupported();
return $this->IsActive() ? $this->oDriver->ContactSave($oAccount, $oContact) : false;
}
/**
* @param \RainLoop\Account $oAccount
* @param array $aContactIds
*
* @return bool
*/
public function DeleteContacts($oAccount, $aContactIds)
{
return $this->IsActive() ? $this->oDriver->DeleteContacts($oAccount, $aContactIds) : false;
}
/**
* @param \RainLoop\Account $oAccount
* @param int $iOffset = 0
* @param type $iLimit = 20
* @param string $sSearch = ''
* @param bool $bAutoOnly = false
*
* @return array
*/
public function GetContacts($oAccount,
$iOffset = 0, $iLimit = 20, $sSearch = '', $bAutoOnly = false)
{
return $this->IsActive() ? $this->oDriver->GetContacts($oAccount,
$iOffset, $iLimit, $sSearch, $bAutoOnly) : array();
}
/**
* @param \RainLoop\Account $oAccount
* @param string $sSearch
* @param int $iLimit = 20
*
* @return array
*
* @throws \InvalidArgumentException
*/
public function GetSuggestions($oAccount, $sSearch, $iLimit = 20)
{
return $this->IsActive() ? $this->oDriver->GetSuggestions($oAccount, $sSearch, $iLimit) : array();
}
/**
* @param \RainLoop\Account $oAccount
* @param array $aEmails
*
* @return bool
*/
public function IncFrec($oAccount, $aEmails)
{
return $this->IsActive() ? $this->oDriver->IncFrec($oAccount, $aEmails) : false;
}
/**
@ -46,31 +109,7 @@ class PersonalAddressBook extends \RainLoop\Providers\AbstractProvider
*/
public function SynchronizeStorage()
{
return $this->IsSupported() && \method_exists($this->oDriver, 'SynchronizeStorage') &&
return $this->IsActive() && \method_exists($this->oDriver, 'SynchronizeStorage') &&
$this->oDriver->SynchronizeStorage();
}
/**
* @param \RainLoop\Account $oAccount
* @param string $sSearch
*
* @return array
*
* @throws \InvalidArgumentException
*/
public function GetSuggestions($oAccount, $sSearch)
{
return $this->IsActive() ? $this->oDriver->GetSuggestions($oAccount, $sSearch) : array();
}
/**
* @param \RainLoop\Account $oAccount
* @param array $aEmail
*
* @return bool
*/
public function IncFrec($oAccount, $aEmail)
{
return $this->IsActive() ? $this->oDriver->IncFrec($oAccount, $aEmail) : false;
}
}

View file

@ -5,24 +5,29 @@ namespace RainLoop\Providers\PersonalAddressBook\Classes;
class Contact
{
/**
* @var int
* @var string
*/
public $IdContact;
/**
* @var string
*/
public $DisplayInList;
public $Display;
/**
* @var int
* @var string
*/
public $Type;
public $DisplayName;
/**
* @var string
*/
public $DisplayEmail;
/**
* @var bool
*/
public $CanBeChanged;
public $Auto;
/**
* @var int
@ -32,7 +37,7 @@ class Contact
/**
* @var array
*/
public $TagsIds;
public $Tags;
/**
* @var array
@ -46,13 +51,14 @@ class Contact
public function Clear()
{
$this->IdContact = 0;
$this->IdContact = '';
$this->IdUser = 0;
$this->DisplayInList = '';
$this->Type = \RainLoop\Providers\PersonalAddressBook\Enumerations\ContactType::DEFAULT_;
$this->CanBeChanged = false;
$this->Display = '';
$this->DisplayName = '';
$this->DisplayEmail = '';
$this->Auto = false;
$this->Changed = \time();
$this->TagsIds = array();
$this->Tags = array();
$this->Properties = array();
}
@ -79,8 +85,11 @@ class Contact
}
}
}
$this->DisplayInList = 0 < \strlen($sDisplayName) ? $sDisplayName : (!empty($sDisplayEmail) ? $sDisplayEmail : '');
$this->DisplayName = $sDisplayName;
$this->DisplayEmail = $sDisplayEmail;
$this->Display = 0 < \strlen($sDisplayName) ? $sDisplayName : (!empty($sDisplayEmail) ? $sDisplayEmail : '');
}
/**

View file

@ -88,8 +88,8 @@ class Property
if ($this->IsPhone())
{
$sPhone = $this->Value;
$sPhone = \preg_replace('^[+]+', '', $sPhone);
$sPhone = \preg_replace('[^\d]', '', $sPhone);
$sPhone = \preg_replace('/^[+]+/', '', $sPhone);
$sPhone = \preg_replace('/[^\d]/', '', $sPhone);
$this->ValueClear = $sPhone;
}
}

View file

@ -1,10 +0,0 @@
<?php
namespace RainLoop\Providers\PersonalAddressBook\Enumerations;
class ContactType
{
const DEFAULT_ = 0;
const SHARE = 1;
const AUTO = 2;
}

View file

@ -8,9 +8,9 @@ class PropertyType
const FULLNAME = 10;
const NAME = 15;
const SURNAME = 16;
const MIDDLENAME = 17;
const FIRST_NAME = 15;
const SUR_NAME = 16;
const MIDDLE_NAME = 17;
const NICK = 18;
const EMAIl_PERSONAL = 30;
@ -25,8 +25,9 @@ class PropertyType
const MOBILE_BUSSINES = 61;
const MOBILE_OTHER = 62;
const FAX_BUSSINES = 70;
const FAX_OTHER = 71;
const FAX_PERSONAL = 70;
const FAX_BUSSINES = 71;
const FAX_OTHER = 72;
const FACEBOOK = 90;
const SKYPE = 91;

View file

@ -1,620 +0,0 @@
<?php
namespace RainLoop\Providers\PersonalAddressBook;
use
\RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType,
\RainLoop\Providers\PersonalAddressBook\Enumerations\ContactType
;
class MySqlPersonalAddressBook
extends \RainLoop\Common\PdoAbstract
implements \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface
{
/**
* @return bool
*/
public function IsSupported()
{
$aDrivers = \class_exists('PDO') ? \PDO::getAvailableDrivers() : array();
return \is_array($aDrivers) ? \in_array('mysql', $aDrivers) : false;
}
/**
* @param int $iUserID
* @param int $iIdContact
* @return array
*/
private function getContactFreq($iUserID, $iIdContact)
{
$aResult = array();
$sTypes = \implode(',', array(
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER
));
$sSql = 'SELECT `value`, `frec` FROM `rainloop_pab_prop` WHERE id_user = :id_user AND `id_contact` = :id_contact AND `type` IN ('.$sTypes.')';
$aParams = array(
':id_user' => array($iUserID, \PDO::PARAM_INT),
':id_contact' => array($iIdContact, \PDO::PARAM_INT)
);
$oStmt = $this->prepareAndExecute($sSql, $aParams);
if ($oStmt)
{
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
if (\is_array($aFetch))
{
foreach ($aFetch as $aItem)
{
if ($aItem && !empty($aItem['value']) && !empty($aItem['frec']))
{
$aResult[$aItem['value']] = (int) $aItem['frec'];
}
}
}
}
return $aResult;
}
/**
* @param \RainLoop\Account $oAccount
* @param \RainLoop\Providers\PersonalAddressBook\Classes\Contact $oContact
*
* @return bool
*/
public function SetContact($oAccount, &$oContact)
{
$iUserID = $this->getUserId($oAccount->ParentEmailHelper());
$bUpdate = 0 < $oContact->IdContact;
$oContact->UpdateDependentValues();
$oContact->Changed = \time();
if (\RainLoop\Providers\PersonalAddressBook\Enumerations\ContactType::AUTO != $oContact->Type)
{
$aEmail = $oContact->GetEmails();
if (0 < \count($aEmail))
{
$aEmail = \array_map(function ($mItem) {
return \strtolower(\trim($mItem));
}, $aEmail);
$aEmail = \array_filter($aEmail, function ($mItem) {
return !empty($mItem);
});
if (0 < \strlen($aEmail))
{
// clear autocreated contacts
$this->prepareAndExecute(
'DELETE FROM `rainloop_pab_contacts` WHERE `id_user` = :id_user AND `type` = :type AND `display_in_list` IN ('.\implode(',', $aEmail).')',
array(
':id_user' => array($iUserID, \PDO::PARAM_INT),
':type' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ContactType::AUTO, \PDO::PARAM_INT)
)
);
}
}
}
try
{
$this->beginTransaction();
$aFreq = array();
if ($bUpdate)
{
$aFreq = $this->getContactFreq($iUserID, $oContact->IdContact);
$sSql = 'UPDATE `rainloop_pab_contacts` SET `display_in_list` = :display_in_list, '.
'`type` = :type, `changed` = :changed WHERE id_user = :id_user AND `id_contact` = :id_contact';
$this->prepareAndExecute($sSql,
array(
':id_user' => array($iUserID, \PDO::PARAM_INT),
':id_contact' => array($oContact->IdContact, \PDO::PARAM_INT),
':display_in_list' => array($oContact->DisplayInList, \PDO::PARAM_STR),
':type' => array($oContact->Type, \PDO::PARAM_INT),
':changed' => array($oContact->Changed, \PDO::PARAM_INT),
)
);
// clear previos props
$this->prepareAndExecute(
'DELETE FROM `rainloop_pab_prop` WHERE `id_user` = :id_user AND `id_contact` = :id_contact',
array(
':id_user' => array($iUserID, \PDO::PARAM_INT),
':id_contact' => array($oContact->IdContact, \PDO::PARAM_INT)
)
);
}
else
{
$sSql = 'INSERT INTO `rainloop_pab_contacts` '.
'(`id_user`, `display_in_list`, `type`, `changed`) VALUES '.
'(:id_user, :display_in_list, :type, :changed)';
$this->prepareAndExecute($sSql,
array(
':id_user' => array($iUserID, \PDO::PARAM_INT),
':display_in_list' => array($oContact->DisplayInList, \PDO::PARAM_STR),
':type' => array($oContact->Type, \PDO::PARAM_INT),
':changed' => array($oContact->Changed, \PDO::PARAM_INT)
)
);
$sLast = $this->lastInsertId('id_contact');
if (\is_numeric($sLast) && 0 < (int) $sLast)
{
$oContact->IdContact = (int) $sLast;
}
}
if (0 < $oContact->IdContact)
{
$aParams = array();
foreach ($oContact->Properties as /* @var $oProp \RainLoop\Providers\PersonalAddressBook\Classes\Property */ $oProp)
{
$iFreq = $oProp->Frec;
if ($oProp->IsEmail() && isset($aFreq[$oProp->Value]))
{
$iFreq = $aFreq[$oProp->Value];
}
$aParams[] = array(
':id_contact' => array($oContact->IdContact, \PDO::PARAM_INT),
':id_user' => array($iUserID, \PDO::PARAM_INT),
':type' => array($oProp->Type, \PDO::PARAM_INT),
':type_custom' => array($oProp->TypeCustom, \PDO::PARAM_STR),
':value' => array($oProp->Value, \PDO::PARAM_STR),
':value_custom' => array($oProp->ValueClear, \PDO::PARAM_STR),
':frec' => array($iFreq, \PDO::PARAM_INT),
);
}
$sSql = 'INSERT INTO `rainloop_pab_prop` '.
'(`id_contact`, `id_user`, `type`, `type_custom`, `value`, `value_custom`, `frec`) VALUES '.
'(:id_contact, :id_user, :type, :type_custom, :value, :value_custom, :frec)';
$this->prepareAndExecute($sSql, $aParams, true);
}
}
catch (\Exception $oException)
{
$this->rollBack();
throw $oException;
}
$this->commit();
return 0 < $oContact->IdContact;
}
/**
* @param \RainLoop\Account $oAccount
* @param array $aContactIds
*
* @return bool
*/
public function DeleteContacts($oAccount, $aContactIds)
{
$iUserID = $this->getUserId($oAccount->ParentEmailHelper());
$aContactIds = \array_filter($aContactIds, function (&$mItem) {
$mItem = (int) $mItem;
return 0 < $mItem;
});
if (0 === \count($aContactIds))
{
return false;
}
return !!$this->prepareAndExecute(
'DELETE FROM `rainloop_pab_contacts` WHERE `id_user` = :id_user AND `id_contact` IN ('.\implode(',', $aContactIds).')',
array(':id_user' => array($iUserID, \PDO::PARAM_INT)));
}
/**
* @param \RainLoop\Account $oAccount
* @param int $iType = \RainLoop\Providers\PersonalAddressBook\Enumerations\ContactType::DEFAULT_
* @param int $iOffset = 0
* @param type $iLimit = 20
* @param string $sSearch = ''
*
* @return array
*/
public function GetContacts($oAccount,
$iType = \RainLoop\Providers\PersonalAddressBook\Enumerations\ContactType::DEFAULT_,
$iOffset = 0, $iLimit = 20, $sSearch = '')
{
$iOffset = 0 <= $iOffset ? $iOffset : 0;
$iLimit = 0 < $iLimit ? (int) $iLimit : 20;
$sSearch = \trim($sSearch);
$iUserID = $this->getUserId($oAccount->ParentEmailHelper());
if (!\in_array($iType, array(ContactType::SHARE, ContactType::AUTO)))
{
$iType = ContactType::DEFAULT_;
}
$sSql = 'SELECT * FROM `rainloop_pab_contacts` WHERE id_user = :id_user AND `type` = :type';
$aParams = array(
':id_user' => array($iUserID, \PDO::PARAM_INT),
':type' => array($iType, \PDO::PARAM_INT)
);
if (0 < \strlen($sSearch))
{
$sSql .= ' AND `id_contact` IN ('.
'SELECT DISTINCT `id_contact` FROM `rainloop_pab_prop` WHERE id_user = :id_user AND `value` LIKE :search ESCAPE \'=\''.
')';
$aParams[':search'] = array($this->specialConvertSearchValue($sSearch, '='), \PDO::PARAM_STR);
}
$sSql .= ' ORDER BY `display_in_list` ASC LIMIT :limit OFFSET :offset';
$aParams[':limit'] = array($iLimit, \PDO::PARAM_INT);
$aParams[':offset'] = array($iOffset, \PDO::PARAM_INT);
$oStmt = $this->prepareAndExecute($sSql, $aParams);
if ($oStmt)
{
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
$aContacts = array();
$aIdContacts = array();
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)
{
$aIdContacts[] = $iIdContact;
$oContact = new \RainLoop\Providers\PersonalAddressBook\Classes\Contact();
$oContact->IdContact = $iIdContact;
$oContact->DisplayInList = isset($aItem['display_in_list']) ? (string) $aItem['display_in_list'] : '';
$oContact->Type = isset($aItem['type']) ? (int) $aItem['type'] :
\RainLoop\Providers\PersonalAddressBook\Enumerations\ContactType::DEFAULT_;
$oContact->Changed = isset($aItem['changed']) ? (int) $aItem['changed'] : 0;
$oContact->CanBeChanged = true;
$aContacts[$iIdContact] = $oContact;
}
}
}
unset($aFetch);
if (0 < count($aIdContacts))
{
$oStmt->closeCursor();
$sSql = 'SELECT * FROM `rainloop_pab_prop` WHERE id_user = :id_user AND `id_contact` IN ('.\implode(',', $aIdContacts).')';
$oStmt = $this->prepareAndExecute($sSql, array(
':id_user' => array($iUserID, \PDO::PARAM_INT)
));
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['type'], $aItem['value']))
{
$iId = (int) $aItem['id_contact'];
if (0 < $iId && isset($aContacts[$iIdContact]))
{
$oProperty = new \RainLoop\Providers\PersonalAddressBook\Classes\Property();
$oProperty->Type = (int) $aItem['type'];
$oProperty->TypeCustom = isset($aItem['type_custom']) ? (string) $aItem['type_custom'] : '';
$oProperty->Value = (string) $aItem['value'];
$oProperty->ValueClear = isset($aItem['value_clear']) ? (string) $aItem['value_clear'] : '';
$oProperty->Frec = isset($aItem['frec']) ? (int) $aItem['frec'] : 0;
$aContacts[$iIdContact]->Properties[] = $oProperty;
}
}
}
}
unset($aFetch);
return \array_values($aContacts);
}
}
}
return array();
}
/**
* @param \RainLoop\Account $oAccount
* @param string $sSearch
*
* @return array
*
* @throws \InvalidArgumentException
*/
public function GetSuggestions($oAccount, $sSearch)
{
$iLimit = 20;
$sSearch = \trim($sSearch);
if (0 === \strlen($sSearch))
{
throw new \InvalidArgumentException('Empty Search argument');
}
$iUserID = $this->getUserId($oAccount->ParentEmailHelper());
$sTypes = implode(',', array(
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER, PropertyType::FULLNAME
));
$sSql = 'SELECT DISTINCT `id_contact` FROM `rainloop_pab_prop` '.
'WHERE id_user = :id_user AND `type` IN ('.$sTypes.') AND `value` LIKE :search ESCAPE \'=\'';
$aParams = array(
':id_user' => array($iUserID, \PDO::PARAM_INT),
':limit' => array($iLimit, \PDO::PARAM_INT),
':search' => array($this->specialConvertSearchValue($sSearch, '='), \PDO::PARAM_STR)
);
$sSql .= ' ORDER BY `frec` DESC LIMIT :limit';
$aResult = array();
$oStmt = $this->prepareAndExecute($sSql, $aParams);
if ($oStmt)
{
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
$aIdContacts = array();
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)
{
$aIdContacts[] = $iIdContact;
$aResult[$iIdContact] = array('', '');
}
}
}
unset($aFetch);
if (0 < count($aIdContacts))
{
$oStmt->closeCursor();
$sTypes = \implode(',', array(
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER, PropertyType::FULLNAME
));
$sSql = 'SELECT `id_contact`, `type`, `value` FROM `rainloop_pab_prop` '.
'WHERE id_user = :id_user AND `type` IN ('.$sTypes.') AND `id_contact` IN ('.\implode(',', $aIdContacts).')';
$oStmt = $this->prepareAndExecute($sSql, array(
':id_user' => array($iUserID, \PDO::PARAM_INT)
));
if ($oStmt)
{
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
if (\is_array($aFetch) && 0 < \count($aFetch))
{
foreach ($aFetch as $aItem)
{
if ($aItem && isset($aItem['id_contact'], $aItem['type'], $aItem['value']))
{
$iId = $aItem['id_contact'];
if (isset($aResult[$iId]))
{
if ('' === $aResult[$iId][0] && \in_array((int) $aItem['type'],
array(PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER)))
{
$aResult[$iId][0] = $aItem['value'];
}
else if ('' === $aResult[$iId][1] && \in_array((int) $aItem['type'], array(PropertyType::FULLNAME)))
{
$aResult[$iId][1] = $aItem['value'];
}
}
}
}
$aResult = array_filter($aResult, function ($aItem) {
return '' !== $aItem[0];
});
}
unset($aFetch);
return \array_values($aResult);
}
}
}
return array();
}
/**
* @param \RainLoop\Account $oAccount
* @param array $aEmails
*
* @return bool
*/
public function IncFrec($oAccount, $aEmails)
{
$iUserID = $this->getUserId($oAccount->ParentEmailHelper());
$self = $this;
$aEmails = \array_map(function ($mItem) {
return \strtolower(\trim($mItem));
}, $aEmails);
$aEmails = \array_filter($aEmails, function ($mItem) {
return 0 < \strlen($mItem);
});
if (0 === \count($aEmails))
{
throw new \InvalidArgumentException('Empty Emails argument');
}
$sTypes = \implode(',', array(
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER
));
$sSql = 'SELECT `value` FROM `rainloop_pab_prop` WHERE id_user = :id_user AND `type` IN ('.$sTypes.')';
$oStmt = $this->prepareAndExecute($sSql, array(
':id_user' => array($iUserID, \PDO::PARAM_INT)
));
$aExists = array();
if ($oStmt)
{
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
if (\is_array($aFetch) && 0 < \count($aFetch))
{
foreach ($aFetch as $aItem)
{
if ($aItem && !empty($aItem['value']))
{
$aExists[] = \strtolower(\trim($aItem['value']));
}
}
}
}
$aEmailsToCreate = \array_diff($aEmails, $aExists);
if (0 < \count($aEmailsToCreate))
{
$oContact = new \RainLoop\Providers\PersonalAddressBook\Classes\Contact();
foreach ($aEmailsToCreate as $sEmailToCreate)
{
$oContact->Type = \RainLoop\Providers\PersonalAddressBook\Enumerations\ContactType::AUTO;
$oProp = new \RainLoop\Providers\PersonalAddressBook\Classes\Property();
$oProp->Type = \RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType::EMAIl_PERSONAL;
$oProp->Value = $sEmailToCreate;
$oContact->Properties[] = $oProp;
$this->SetContact($oAccount, $oContact);
$oContact->Clear();
}
}
$sSql = 'UPDATE `rainloop_pab_prop` SET `frec` = `frec` + 1 WHERE id_user = :id_user AND `type` IN ('.$sTypes;
$aEmailsQuoted = \array_map(function ($mItem) use ($self) {
return $self->quoteValue($mItem);
}, $aEmails);
if (1 === \count($aEmailsQuoted))
{
$sSql .= ') AND `value` = '.$aEmailsQuoted[0];
}
else
{
$sSql .= ') AND `value` IN ('.\implode(',', $aEmailsQuoted).')';
}
return !!$this->prepareAndExecute($sSql, array(
':id_user' => array($iUserID, \PDO::PARAM_INT),
));
}
/**
* @return bool
*/
public function SynchronizeStorage()
{
return $this->dataBaseUpgrade('mysql-pab-version', array(
1 => array(
// -- rainloop_pab_contacts --
'CREATE TABLE IF NOT EXISTS `rainloop_pab_contacts` (
`id_contact` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`id_user` int(11) UNSIGNED NOT NULL,
`display_in_list` varchar(255) NOT NULL DEFAULT \'\',
`type` int(11) UNSIGNED NOT NULL DEFAULT \'0\',
`changed` int(11) UNSIGNED NOT NULL DEFAULT \'0\',
PRIMARY KEY(`id_contact`),
CONSTRAINT `id_user_fk_rainloop_pab_contacts` FOREIGN KEY (`id_user`)
REFERENCES `rainloop_users` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;',
// -- rainloop_pab_prop --
'CREATE TABLE IF NOT EXISTS `rainloop_pab_prop` (
`id_prop` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`id_contact` int(11) UNSIGNED NOT NULL,
`id_user` int(11) UNSIGNED NOT NULL,
`type` int(11) UNSIGNED NOT NULL,
`type_custom` varchar(50) /*!40101 CHARACTER SET ascii COLLATE ascii_general_ci */ NOT NULL DEFAULT \'\',
`value` varchar(255) NOT NULL DEFAULT \'\',
`value_custom` varchar(255) NOT NULL DEFAULT \'\',
`frec` int(11) UNSIGNED NOT NULL DEFAULT \'0\',
PRIMARY KEY(`id_prop`),
INDEX `id_user_id_contact_index` (`id_user`, `id_contact`),
INDEX `id_user_value_index` (`id_user`, `value`),
CONSTRAINT `id_contact_fk_rainloop_pab_prop` FOREIGN KEY (`id_contact`)
REFERENCES `rainloop_pab_contacts` (`id_contact`) ON DELETE CASCADE ON UPDATE CASCADE
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;',
// -- rainloop_pab_tags --
'CREATE TABLE IF NOT EXISTS `rainloop_pab_tags` (
`id_tag` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`id_contact` int(11) UNSIGNED NOT NULL,
`id_user` int(11) UNSIGNED NOT NULL,
`name` varchar(255) NOT NULL,
PRIMARY KEY(`id_tag`),
UNIQUE `id_user_name_unique` (`id_user`, `name`),
CONSTRAINT `id_user_fk_rainloop_pab_tags` FOREIGN KEY (`id_user`)
REFERENCES `rainloop_users` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;',
// -- rainloop_pab_tags_contacts --
'CREATE TABLE IF NOT EXISTS `rainloop_pab_tags_contacts` (
`id_tag` int(11) UNSIGNED NOT NULL,
`id_contact` int(11) UNSIGNED NOT NULL,
CONSTRAINT `id_contact_fk_rainloop_tags_contacts` FOREIGN KEY (`id_contact`)
REFERENCES `rainloop_pab_contacts` (`id_contact`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `id_tag_fk_rainloop_tags_contacts` FOREIGN KEY (`id_tag`)
REFERENCES `rainloop_pab_tags` (`id_tag`) ON DELETE CASCADE ON UPDATE CASCADE
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;'
)));
}
/**
* @param string $sSearch
*
* @return string
*/
protected function specialConvertSearchValue($sSearch, $sEscapeSign = '=')
{
return '%'.\str_replace(array($sEscapeSign, '_', '%'),
array($sEscapeSign.$sEscapeSign, $sEscapeSign.'_', $sEscapeSign.'%'), $sSearch).'%';
}
}

View file

@ -4,8 +4,60 @@ namespace RainLoop\Providers\PersonalAddressBook;
interface PersonalAddressBookInterface
{
/**
* @return string
*/
public function Version();
/**
* @return bool
*/
public function IsSupported();
/**
* @param \RainLoop\Account $oAccount
* @param \RainLoop\Providers\PersonalAddressBook\Classes\Contact $oContact
*
* @return bool
*/
public function ContactSave($oAccount, &$oContact);
/**
* @param \RainLoop\Account $oAccount
* @param array $aContactIds
*
* @return bool
*/
public function DeleteContacts($oAccount, $aContactIds);
/**
* @param \RainLoop\Account $oAccount
* @param int $iOffset = 0
* @param type $iLimit = 20
* @param string $sSearch = ''
* @param bool $bAutoOnly = false
*
* @return array
*/
public function GetContacts($oAccount,
$iOffset = 0, $iLimit = 20, $sSearch = '', $bAutoOnly = false);
/**
* @param \RainLoop\Account $oAccount
* @param string $sSearch
* @param int $iLimit = 20
*
* @return array
*
* @throws \InvalidArgumentException
*/
public function GetSuggestions($oAccount, $sSearch, $iLimit = 20);
/**
* @param \RainLoop\Account $oAccount
* @param array $aEmails
*
* @return bool
*/
public function IncFrec($oAccount, $aEmails);
}

View file

@ -1,109 +0,0 @@
-- RainLoop Webmail initial contacts database structure
/*!40014 SET FOREIGN_KEY_CHECKS=0 */;
-- Table structure for table `rainloop_system`
CREATE TABLE IF NOT EXISTS `rainloop_system` (
`name` varchar(50) NOT NULL,
`value_int` int(11) UNSIGNED NOT NULL DEFAULT '0',
`value_str` varchar(255) NOT NULL DEFAULT ''
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
-- Table structure for table `rainloop_users`
CREATE TABLE IF NOT EXISTS `rainloop_users` (
`id_user` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`email` varchar(255) /*!40101 CHARACTER SET ascii COLLATE ascii_general_ci */ NOT NULL,
UNIQUE `email_unique` (`email`),
PRIMARY KEY(`id_user`)
) /*!40000 ENGINE=INNODB */;
-- Table structure for table `rainloop_pab_contacts`
CREATE TABLE IF NOT EXISTS `rainloop_pab_contacts` (
`id_contact` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`id_user` int(11) UNSIGNED NOT NULL,
`display_in_list` varchar(255) NOT NULL DEFAULT '',
`type` int(11) UNSIGNED NOT NULL DEFAULT '0',
`changed` int(11) UNSIGNED NOT NULL DEFAULT '0',
CONSTRAINT `id_user_fk_rainloop_pab_contacts` FOREIGN KEY (`id_user`)
REFERENCES `rainloop_users` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY(`id_contact`)
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
-- Table structure for table `rainloop_pab_prop`
CREATE TABLE IF NOT EXISTS `rainloop_pab_prop` (
`id_prop` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`id_contact` int(11) UNSIGNED NOT NULL,
`id_user` int(11) UNSIGNED NOT NULL,
`type` int(11) UNSIGNED NOT NULL,
`type_custom` varchar(50) /*!40101 CHARACTER SET ascii COLLATE ascii_general_ci */ NOT NULL DEFAULT '',
`value` varchar(255) NOT NULL DEFAULT '',
`value_custom` varchar(255) NOT NULL DEFAULT '',
`frec` int(11) UNSIGNED NOT NULL DEFAULT '0',
INDEX `id_user_id_contact_index` (`id_user`, `id_contact`),
INDEX `id_user_value_index` (`id_user`, `value`),
CONSTRAINT `id_contact_fk_rainloop_pab_prop` FOREIGN KEY (`id_contact`)
REFERENCES `rainloop_pab_contacts` (`id_contact`) ON DELETE CASCADE ON UPDATE CASCADE
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
-- Table structure for table `rainloop_pab_tags`
CREATE TABLE IF NOT EXISTS `rainloop_pab_tags` (
`id_tag` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`id_contact` int(11) UNSIGNED NOT NULL,
`id_user` int(11) UNSIGNED NOT NULL,
`name` varchar(255) NOT NULL,
UNIQUE `id_user_name_unique` (`id_user`, `name`),
CONSTRAINT `id_user_fk_rainloop_pab_tags` FOREIGN KEY (`id_user`)
REFERENCES `rainloop_users` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY(`id_tag`)
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
-- Table structure for table `rainloop_pab_tags_contacts`
CREATE TABLE IF NOT EXISTS `rainloop_pab_tags_contacts` (
`id_tag` int(11) UNSIGNED NOT NULL,
`id_contact` int(11) UNSIGNED NOT NULL,
UNIQUE `id_user_name_unique` (`id_user`, `name`),
CONSTRAINT `id_contact_fk_rainloop_tags_contacts` FOREIGN KEY (`id_contact`)
REFERENCES `rainloop_pab_contacts` (`id_contact`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `id_tag_fk_rainloop_tags_contacts` FOREIGN KEY (`id_tag`)
REFERENCES `rainloop_pab_tags` (`id_tag`) ON DELETE CASCADE ON UPDATE CASCADE
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
-- RainLoop Webmail update contacts database structure
DELIMITER $$
DROP PROCEDURE IF EXISTS rainloop_pab_upgrade_database $$
CREATE PROCEDURE rainloop_pab_upgrade_database()
BEGIN
DECLARE new_version INT DEFAULT 1;
DECLARE current_version INT DEFAULT 0;
SELECT IFNULL(MAX(`value_int`), 0) INTO current_version FROM `rainloop_system` WHERE `name` = 'rainloop-pab-db-version';
-- TODO
--
-- IF current_version < 1 THEN
-- ALTER TABLE `rainloop_pab_prop` ADD INDEX `id_user_id_contact_index` (`id_user`, `id_contact`);
-- END IF;
--
-- IF current_version < 2 THEN
-- ALTER TABLE `rainloop_pab_prop` ADD INDEX `id_user_id_contact_index` (`id_user`, `id_contact`);
-- END IF;
DELETE FROM `rainloop_system` WHERE `name` = 'rainloop-pab-db-version' AND `value_int` <= new_version;
INSERT INTO `rainloop_system` (`name`, `value_int`) VALUES ('rainloop-pab-db-version', new_version);
END$$
-- TODO
-- CALL rainloop_pab_upgrade_database() $$
DROP PROCEDURE IF EXISTS rainloop_pab_upgrade_database $$
DELIMITER ;
/*!40014 SET FOREIGN_KEY_CHECKS=1 */;

View file

@ -9,15 +9,6 @@
password to something else now.
</div>
</div>
<div class="row" data-bind="visible: !contactsSupported">
<div class="alert span8">
<h4>Notice!</h4>
<br />
<strong>Contacts</strong> functions are not supported.
<br />
You need to install or enable <strong>PDO (sqlite)</strong> exstenstion on your server.
</div>
</div>
<div class="form-horizontal">
<div class="legend">
General

View file

@ -1,104 +1,121 @@
<div class="popups">
<div class="modal hide b-contacts-content" data-bind="modal: modalVisibility">
<div class="modal-header b-header-toolbar g-ui-user-select-none">
<button type="button" class="close" data-bind="command: cancelCommand">&times;</button>
<a class="btn button-create-contact" data-bind="command: newCommand">
<i class="icon-plus"></i>
&nbsp;&nbsp;
<span class="i18n" data-i18n-text="CONTACTS/BUTTON_ADD_CONTACT"></span>
</a>
<a class="btn btn-success button-new-message" data-bind="command: newMessageCommand">
<i class="icon-envelope icon-white"></i>
</a>
<a class="btn btn-danger button-delete" data-bind="command: deleteCommand">
<i class="icon-trash icon-white"></i>
<span data-bind="text: 1 < contactsCheckedOrSelected().length ? ' (' + contactsCheckedOrSelected().length + ')' : ''"></span>
</a>
</div>
<div class="modal-body" style="position: relative">
<div class="b-list-toopbar">
<input class="i18n span3 e-search" type="text" placeholder="Search" data-18n-placeholder="CONTACS/SEARCH_INPUT_PLACEHOLDER" data-bind="value: search" />
</div>
<div class="b-list-content g-ui-user-select-none" data-bind="nano: true, css: {'hideContactListCheckbox': !useCheckboxesInList()}">
<div class="content g-scrollbox">
<div class="content-wrapper">
<div class="listClear" data-bind="visible: viewClearSearch() && '' !== search()">
<span class="g-ui-link i18n" data-i18n-text="CONTACTS/CLEAR_SEARCH" data-bind="command: clearCommand"></span>
</div>
<div class="listEmptyList" data-bind="visible: 0 === contacts().length && '' === search() && !contacts.loading()">
<span class="i18n" data-i18n-text="CONTACTS/EMPTY_LIST"></span>
</div>
<div class="listEmptyListLoading" data-bind="visible: 0 === contacts().length && '' === search() && contacts.loading()">
<span class="i18n" data-i18n-text="CONTACTS/LIST_LOADING"></span><span class="textLoadingAnimationD1">.</span><span class="textLoadingAnimationD2">.</span><span class="textLoadingAnimationD3">.</span>
</div>
<div class="listEmptySearchList" data-bind="visible: 0 === contacts().length && '' !== search() && !contacts.loading()">
<span class="i18n" data-i18n-text="CONTACTS/EMPTY_SEARCH"></span>
</div>
<div class="e-contact-foreach" data-bind="foreach: contacts, visible: 0 < contacts().length">
<div class="e-contact-item g-ui-user-select-none" data-bind="css: lineAsCcc()">
<div class="sidebarParent">
&nbsp;
</div>
<div class="delimiter"></div>
<div class="wrapper">
<div class="checkedParent">
<i class="checkboxItem" data-bind="css: checked() || selected() ? 'checkboxMessage icon-checkbox-checked' : 'checkboxMessage icon-checkbox-unchecked'"></i>
</div>
<div class="nameParent actionHandle">
<span class="listName" data-bind="text: listName"></span>
&nbsp;
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="b-view-content" data-bind="nano: true">
<div class="content g-scrollbox">
<div class="content-wrapper">
<div class="b-contact-view-desc" data-bind="visible: emptySelection">
<span class="i18n" data-i18n-text="CONTACTS/CONTACT_VIEW_DESC"></span>
</div>
<div data-bind="visible: !emptySelection()">
<div class="form-horizontal top-part">
<div class="control-group">
<div class="control-label" data-bind="initDom: imageUploader">
<div class="image-wrapper" style="width: 100px; height: 100px;">
<img data-bind="initDom: imageDom" style="width: 100px; height: 100px;" />
</div>
</div>
<div class="controls">
<div class="top-row">
<span class="contactEmptyValueClick" data-bind="visible: !viewName.focused() && '' === viewName(), click: function() { viewName.focused(true); }">display name</span>
<span class="contactValueClick" data-bind="visible: !viewName.focused() && '' !== viewName(), click: function() { viewName.focused(true); }, text: viewName"></span>
<input class="contactValueInput span5" type="text" placeholder="display name" data-bind="value: viewName, visible: viewName.focused, hasfocus: viewName.focused, onEnter: function () { viewName.focused(false); }">
</div>
<div class="top-row" data-bind="css: { hasError: viewEmail.hasError() }">
<span class="contactEmptyValueClick" data-bind="visible: !viewEmail.focused() && '' === viewEmail(), click: function() { viewEmail.focused(true); }">email</span>
<span class="contactValueClick" data-bind="visible: !viewEmail.focused() && !viewEmail.hasError() && '' !== viewEmail(), click: function() { viewEmail.focused(true); }, text: viewEmail"></span>
<input class="contactValueInput span5" type="text" placeholder="email" data-bind="value: viewEmail, visible: viewEmail.hasError() || viewEmail.focused(), hasfocus: viewEmail.focused, onEnter: function () { viewEmail.focused(false); }">
</div>
</div>
</div>
<div class="control-group">
<div class="control-label">
</div>
<div class="controls">
</div>
</div>
</div>
<button class="btn button-save-contact" data-bind="command: saveCommand">
<i data-bind="css: {'icon-ok': !viewSaving(), 'icon-spinner-2 animated': viewSaving()}"></i>
&nbsp;&nbsp;
<span class="i18n" data-i18n-text="CONTACTS/BUTTON_CREATE_CONTACT" data-bind="visible: '' === viewID()"></span>
<span class="i18n" data-i18n-text="CONTACTS/BUTTON_UPDATE_CONTACT" data-bind="visible: '' !== viewID()"></span>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="popups">
<div class="modal hide b-contacts-content" data-bind="modal: modalVisibility">
<div class="modal-header b-header-toolbar g-ui-user-select-none">
<button type="button" class="close" data-bind="command: cancelCommand">&times;</button>
<a class="btn button-create-contact" data-bind="command: newCommand">
<i class="icon-plus"></i>
&nbsp;&nbsp;
<span class="i18n" data-i18n-text="CONTACTS/BUTTON_ADD_CONTACT"></span>
</a>
<a class="btn btn-success button-new-message" data-bind="command: newMessageCommand">
<i class="icon-envelope icon-white"></i>
</a>
<a class="btn btn-danger button-delete" data-bind="command: deleteCommand">
<i class="icon-trash icon-white"></i>
<span data-bind="text: 1 < contactsCheckedOrSelected().length ? ' (' + contactsCheckedOrSelected().length + ')' : ''"></span>
</a>
</div>
<div class="modal-body" style="position: relative">
<div class="b-list-toopbar">
<input class="i18n span3 e-search" type="text" placeholder="Search" data-18n-placeholder="CONTACS/SEARCH_INPUT_PLACEHOLDER" data-bind="value: search" />
</div>
<div class="b-list-content g-ui-user-select-none" data-bind="nano: true, css: {'hideContactListCheckbox': !useCheckboxesInList()}">
<div class="content g-scrollbox">
<div class="content-wrapper">
<div class="listClear" data-bind="visible: viewClearSearch() && '' !== search()">
<span class="g-ui-link i18n" data-i18n-text="CONTACTS/CLEAR_SEARCH" data-bind="command: clearCommand"></span>
</div>
<div class="listEmptyList" data-bind="visible: 0 === contacts().length && '' === search() && !contacts.loading()">
<span class="i18n" data-i18n-text="CONTACTS/EMPTY_LIST"></span>
</div>
<div class="listEmptyListLoading" data-bind="visible: 0 === contacts().length && '' === search() && contacts.loading()">
<span class="i18n" data-i18n-text="CONTACTS/LIST_LOADING"></span><span class="textLoadingAnimationD1">.</span><span class="textLoadingAnimationD2">.</span><span class="textLoadingAnimationD3">.</span>
</div>
<div class="listEmptySearchList" data-bind="visible: 0 === contacts().length && '' !== search() && !contacts.loading()">
<span class="i18n" data-i18n-text="CONTACTS/EMPTY_SEARCH"></span>
</div>
<div class="e-contact-foreach" data-bind="foreach: contacts, visible: 0 < contacts().length">
<div class="e-contact-item g-ui-user-select-none" data-bind="css: lineAsCcc()">
<div class="sidebarParent">
&nbsp;
</div>
<div class="delimiter"></div>
<div class="wrapper">
<div class="checkedParent">
<i class="checkboxItem" data-bind="css: checked() || selected() ? 'checkboxMessage icon-checkbox-checked' : 'checkboxMessage icon-checkbox-unchecked'"></i>
</div>
<div class="nameParent actionHandle">
<span class="listName" data-bind="text: display"></span>
&nbsp;
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="b-view-content" data-bind="nano: true">
<div class="content g-scrollbox">
<div class="content-wrapper">
<div class="b-contact-view-desc" data-bind="visible: emptySelection">
<span class="i18n" data-i18n-text="CONTACTS/CONTACT_VIEW_DESC"></span>
</div>
<div data-bind="visible: !emptySelection()">
<div class="form-horizontal top-part">
<div class="control-group">
<label class="control-label">
<span class="i18n">Display name</span>
</label>
<div class="controls" data-bind="foreach: viewPropertiesNames">
<div class="property-line">
<input type="text" class="contactValueInput" data-bind="value: value, valueUpdate: 'keyup'" />
</div>
</div>
</div>
<div class="control-group">
<label class="control-label">
<span class="i18n">Emails</span>
</label>
<div class="controls">
<div data-bind="foreach: viewPropertiesEmails">
<div class="property-line">
<input type="email" class="contactValueInput" data-bind="value: value, hasFocus: focused, valueUpdate: 'keyup'" />
</div>
</div>
<div class="g-ui-link add-link" data-bind="click: addNewEmail">Add an email address</div>
</div>
</div>
<div class="control-group">
<label class="control-label">
<span class="i18n">Phones</span>
</label>
<div class="controls">
<div data-bind="foreach: viewPropertiesPhones">
<div class="property-line">
<input type="email" class="contactValueInput" data-bind="value: value, hasFocus: focused, valueUpdate: 'keyup'" />
</div>
</div>
<div class="g-ui-link add-link" data-bind="click: addNewPhone">Add a phone</div>
</div>
</div>
<div class="control-group">
<div class="controls">
<br />
<br />
</div>
</div>
</div>
<button class="btn button-save-contact" data-bind="command: saveCommand">
<i data-bind="css: {'icon-ok': !viewSaving(), 'icon-spinner-2 animated': viewSaving()}"></i>
&nbsp;&nbsp;
<span class="i18n" data-i18n-text="CONTACTS/BUTTON_CREATE_CONTACT" data-bind="visible: '' === viewID()"></span>
<span class="i18n" data-i18n-text="CONTACTS/BUTTON_UPDATE_CONTACT" data-bind="visible: '' !== viewID()"></span>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>