Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
addressbook.php
1<?php
2
4
9
15{
16 private function editContact($contactData)
17 {
18 $id = $contactData['ID'];
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
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
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}
static addContactsBatch($contactsData)
static getRow(array $parameters)
static update($primary, array $data)