Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
addressbook.php
1
<?php
2
3
namespace
Bitrix\Mail\Controller
;
4
5
use
Bitrix\Main\Engine\Controller
;
6
use
Bitrix\Main\Loader
;
7
use
Bitrix\Mail\Internals\MailContactTable
;
8
use
Bitrix\Main\Error
;
9
14
class
AddressBook
extends
Controller
15
{
16
private
function
editContact($contactData)
17
{
18
$id = $contactData[
'ID'
];
19
$userID =
MailContactTable::getRow
(
20
[
21
'filter'
=> [
'ID'
=> $id],
22
'select'
=> [
'USER_ID'
],
23
]
24
)[
'USER_ID'
];
25
26
if
(!($this->
getCurrentUser
()->getId() === $userID &&
27
$contactData[
'NAME'
] <>
""
&&
28
check_email($contactData[
'EMAIL'
])))
29
{
30
return
false
;
31
}
32
33
MailContactTable::update
(
34
$id,
35
[
36
'ICON'
=> [
37
'INITIALS'
=> $contactData[
'INITIALS'
],
38
'COLOR'
=> $contactData[
'COLOR'
],
39
],
40
'NAME'
=> trim($contactData[
'NAME'
]),
41
'EMAIL'
=> $contactData[
'EMAIL'
],
42
]
43
);
44
}
45
46
private
function
isUserAdmin()
47
{
48
global $USER;
49
if
(!(is_object($USER) && $USER->IsAuthorized()))
50
{
51
return
false
;
52
}
53
54
return
(
bool
)($USER->isAdmin() || $USER->canDoOperation(
'bitrix24_config'
));
55
}
56
63
public
function
removeContactsAction
($idSet)
64
{
65
if
(!Loader::includeModule(
'mail'
))
66
{
67
return
false
;
68
}
69
70
foreach
($idSet as $id)
71
{
72
$contactToDelete =
MailContactTable::getRow
(
73
[
74
'filter'
=> [
75
'=ID'
=> $id,
76
'=USER_ID'
=> $this->
getCurrentUser
()->getId(),
77
],
78
]
79
);
80
81
if
(is_null($contactToDelete))
82
{
83
return
false
;
84
}
85
86
MailContactTable::delete
($id);
87
}
88
89
return
true
;
90
}
91
98
public
function
saveContactAction
($contactData)
99
{
100
if
(!Loader::includeModule(
'mail'
))
101
{
102
return
false
;
103
}
104
105
$contactData[
'EMAIL'
] = mb_strtolower($contactData[
'EMAIL'
]);
106
107
if
(!check_email($contactData[
'EMAIL'
]))
108
{
109
return
false
;
110
}
111
112
if
($contactData[
'ID'
] !==
'new'
)
113
{
114
return
$this->editContact($contactData);
115
}
116
else
117
{
118
$contactsData[] = [
119
'USER_ID'
=> $this->
getCurrentUser
()->getId(),
120
'NAME'
=> $contactData[
'NAME'
],
121
'ICON'
=> [
122
'INITIALS'
=> $contactData[
'INITIALS'
],
123
'COLOR'
=> $contactData[
'COLOR'
],
124
],
125
'EMAIL'
=> $contactData[
'EMAIL'
],
126
'ADDED_FROM'
=>
'MANUAL'
,
127
];
128
129
$result =
MailContactTable::addContactsBatch
($contactsData);
130
131
iF($result !==
true
)
132
{
133
$this->
addError
(
new
Error
($result));
134
return
false
;
135
}
136
}
137
138
return
true
;
139
}
140
}
Bitrix\Mail\Controller\AddressBook
Definition
addressbook.php:15
Bitrix\Mail\Controller\AddressBook\removeContactsAction
removeContactsAction($idSet)
Definition
addressbook.php:63
Bitrix\Mail\Controller\AddressBook\saveContactAction
saveContactAction($contactData)
Definition
addressbook.php:98
Bitrix\Mail\Internals\MailContactTable
Definition
mailcontact.php:29
Bitrix\Mail\Internals\MailContactTable\addContactsBatch
static addContactsBatch($contactsData)
Definition
mailcontact.php:81
Bitrix\Main\Engine\Controller
Definition
controller.php:32
Bitrix\Main\Engine\Controller\addError
addError(Error $error)
Definition
controller.php:1051
Bitrix\Main\Engine\Controller\getCurrentUser
getCurrentUser()
Definition
controller.php:264
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Main\ORM\Data\DataManager\getRow
static getRow(array $parameters)
Definition
datamanager.php:410
Bitrix\Main\ORM\Data\DataManager\delete
static delete($primary)
Definition
datamanager.php:1632
Bitrix\Main\ORM\Data\DataManager\update
static update($primary, array $data)
Definition
datamanager.php:1246
Bitrix\Mail\Controller
Definition
addressbook.php:3
Bitrix\Sender\Internals\QueryController
Definition
action.php:8
modules
mail
lib
controller
addressbook.php
Создано системой
1.10.0