1
|
|
|
<?php |
2
|
|
|
/* For licensing terms, see /license.txt */ |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Responses to AJAX calls. |
6
|
|
|
*/ |
7
|
|
|
require_once __DIR__.'/../global.inc.php'; |
8
|
|
|
|
9
|
|
|
$action = $_REQUEST['a'] ?? null; |
10
|
|
|
|
11
|
|
|
$isAllowedToEdit = api_is_allowed_to_edit(); |
12
|
|
|
$courseInfo = api_get_course_info(); |
13
|
|
|
$courseCode = api_get_course_id(); |
14
|
|
|
$courseId = api_get_course_int_id(); |
15
|
|
|
$groupId = api_get_group_id(); |
16
|
|
|
$sessionId = api_get_session_id(); |
17
|
|
|
$currentUserId = api_get_user_id(); |
18
|
|
|
|
19
|
|
|
$isTutor = false; |
20
|
|
|
if (!empty($groupId)) { |
21
|
|
|
$groupInfo = GroupManager::get_group_properties($groupId); |
22
|
|
|
$isTutor = GroupManager::is_tutor_of_group(api_get_user_id(), $groupInfo); |
23
|
|
|
if ($isTutor) { |
24
|
|
|
$isAllowedToEdit = true; |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
switch ($action) { |
29
|
|
|
case 'preview': |
30
|
|
|
$userInCourse = false; |
31
|
|
|
if (CourseManager::is_user_subscribed_in_course($currentUserId, CourseManager::get_course_code_from_course_id($courseId), $sessionId)) { |
32
|
|
|
$userInCourse = true; |
33
|
|
|
} |
34
|
|
|
$allowToEdit = ( |
35
|
|
|
api_is_allowed_to_edit(false, true) || |
36
|
|
|
(api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous() && $userInCourse) || |
37
|
|
|
($sessionId && api_is_coach() && api_get_configuration_value('allow_coach_to_edit_announcements')) |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
$drhHasAccessToSessionContent = api_drh_can_access_all_session_content(); |
41
|
|
|
if (!empty($sessionId) && $drhHasAccessToSessionContent) { |
42
|
|
|
$allowToEdit = $allowToEdit || api_is_drh(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if ($allowToEdit === false && !empty($groupId)) { |
46
|
|
|
$groupProperties = GroupManager::get_group_properties($groupId); |
47
|
|
|
// Check if user is tutor group |
48
|
|
|
$isTutor = GroupManager::is_tutor_of_group(api_get_user_id(), $groupProperties, $courseId); |
49
|
|
|
if ($isTutor) { |
50
|
|
|
$allowToEdit = true; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
// Last chance ... students can send announcements. |
54
|
|
|
if ($groupProperties['announcements_state'] == GroupManager::TOOL_PRIVATE_BETWEEN_USERS) { |
55
|
|
|
// check if user is a group member to give access |
56
|
|
|
$groupInfo = GroupManager::get_group_properties($groupId); |
57
|
|
|
if (array_key_exists($currentUserId,GroupManager::get_subscribed_users($groupInfo))) { |
58
|
|
|
$allowToEdit = true; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
if ($allowToEdit === false) { |
64
|
|
|
exit; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$users = isset($_REQUEST['users']) ? json_decode($_REQUEST['users']) : ''; |
68
|
|
|
$formParams = []; |
69
|
|
|
if (isset($_REQUEST['form'])) { |
70
|
|
|
parse_str($_REQUEST['form'], $formParams); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$previewGroups = []; |
74
|
|
|
$previewUsers = []; |
75
|
|
|
$previewTotal = []; |
76
|
|
|
if (empty($groupId)) { |
77
|
|
|
if (empty($users) || |
78
|
|
|
(!empty($users) && isset($users[0]) && $users[0] == 'everyone') |
79
|
|
|
) { |
80
|
|
|
// All users in course session |
81
|
|
|
if (empty($sessionId)) { |
82
|
|
|
$students = CourseManager::get_user_list_from_course_code($courseInfo['code']); |
83
|
|
|
} else { |
84
|
|
|
$students = CourseManager::get_user_list_from_course_code($courseInfo['code'], $sessionId); |
85
|
|
|
} |
86
|
|
|
foreach ($students as $student) { |
87
|
|
|
$previewUsers[] = $student['user_id']; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$groupList = GroupManager::get_group_list(null, $courseInfo, null, $sessionId); |
91
|
|
|
foreach ($groupList as $group) { |
92
|
|
|
$previewGroups[] = $group['iid']; |
93
|
|
|
} |
94
|
|
|
} else { |
95
|
|
|
$send_to = CourseManager::separateUsersGroups($users); |
96
|
|
|
// Storing the selected groups |
97
|
|
|
if (is_array($send_to['groups']) && |
98
|
|
|
!empty($send_to['groups']) |
99
|
|
|
) { |
100
|
|
|
$counter = 1; |
101
|
|
|
foreach ($send_to['groups'] as $group) { |
102
|
|
|
$previewGroups[] = $group; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
// Storing the selected users |
107
|
|
|
if (is_array($send_to['users'])) { |
108
|
|
|
$counter = 1; |
109
|
|
|
foreach ($send_to['users'] as $user) { |
110
|
|
|
$previewUsers[] = $user; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
} else { |
115
|
|
|
$send_to_users = CourseManager::separateUsersGroups($users); |
116
|
|
|
$sentToAllGroup = false; |
117
|
|
|
if (empty($send_to_users['groups']) && empty($send_to_users['users'])) { |
118
|
|
|
$previewGroups[] = $groupId; |
119
|
|
|
$sentToAllGroup = true; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
if ($sentToAllGroup === false) { |
123
|
|
|
if (!empty($send_to_users['groups'])) { |
124
|
|
|
foreach ($send_to_users['groups'] as $group) { |
125
|
|
|
$previewGroups[] = $group; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
if (!empty($send_to_users['users'])) { |
130
|
|
|
foreach ($send_to_users['users'] as $user) { |
131
|
|
|
$previewUsers[] = $user; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
if (isset($formParams['send_to_users_in_session']) && $formParams['send_to_users_in_session'] == 1) { |
138
|
|
|
$sessionList = SessionManager::get_session_by_course(api_get_course_int_id()); |
139
|
|
|
|
140
|
|
|
if (!empty($sessionList)) { |
141
|
|
|
foreach ($sessionList as $sessionInfo) { |
142
|
|
|
$sessionId = $sessionInfo['id']; |
143
|
|
|
$userList = CourseManager::get_user_list_from_course_code( |
144
|
|
|
$courseCode, |
145
|
|
|
$sessionId |
146
|
|
|
); |
147
|
|
|
|
148
|
|
|
if (!empty($userList)) { |
149
|
|
|
foreach ($userList as $user) { |
150
|
|
|
$previewUsers[] = $user; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
if (isset($formParams['send_to_hrm_users']) && $formParams['send_to_hrm_users'] == 1) { |
158
|
|
|
foreach ($previewUsers as $userId) { |
159
|
|
|
$userInfo = api_get_user_info($userId); |
160
|
|
|
$drhList = UserManager::getDrhListFromUser($userId); |
161
|
|
|
if (!empty($drhList)) { |
162
|
|
|
foreach ($drhList as $drhInfo) { |
163
|
|
|
$previewUsers[] = $drhInfo['id']; |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
if (isset($formParams['send_me_a_copy_by_email']) && $formParams['send_me_a_copy_by_email'] == 1) { |
170
|
|
|
$previewUsers[] = api_get_user_id(); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
$previewUserNames = []; |
174
|
|
|
$previewGroupNames = []; |
175
|
|
|
|
176
|
|
|
if (!empty($previewGroups)) { |
177
|
|
|
$previewGroups = array_unique($previewGroups); |
178
|
|
|
foreach ($previewGroups as $groupId) { |
179
|
|
|
$groupInfo = GroupManager::get_group_properties($groupId); |
180
|
|
|
$previewGroupNames[] = Display::label($groupInfo['name'], 'info'); |
181
|
|
|
} |
182
|
|
|
$previewTotal = $previewGroupNames; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
if (!empty($previewUsers)) { |
186
|
|
|
$previewUsers = array_unique($previewUsers); |
187
|
|
|
foreach ($previewUsers as $userId) { |
188
|
|
|
$userInfo = api_get_user_info($userId); |
189
|
|
|
$previewUserNames[] = Display::label($userInfo['complete_name']); |
190
|
|
|
} |
191
|
|
|
$previewTotal = array_merge($previewTotal, $previewUserNames); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
$previewTotal = array_map(function ($value) { return ''.$value; }, $previewTotal); |
195
|
|
|
|
196
|
|
|
echo json_encode($previewTotal); |
197
|
|
|
break; |
198
|
|
|
case 'delete_item': |
199
|
|
|
if ($isAllowedToEdit) { |
200
|
|
|
if (empty($_REQUEST['id'])) { |
201
|
|
|
return false; |
202
|
|
|
} |
203
|
|
|
if (!empty($sessionId) && api_is_allowed_to_session_edit(false, true) == false && empty($groupId)) { |
204
|
|
|
return false; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
$list = explode(',', $_REQUEST['id']); |
208
|
|
|
foreach ($list as $itemId) { |
209
|
|
|
if (!api_is_session_general_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $itemId)) { |
210
|
|
|
$result = AnnouncementManager::get_by_id( |
211
|
|
|
api_get_course_int_id(), |
212
|
|
|
$itemId |
213
|
|
|
); |
214
|
|
|
if (!empty($result)) { |
215
|
|
|
$delete = true; |
216
|
|
|
if (!empty($groupId) && $isTutor) { |
217
|
|
|
if ($groupId != $result['to_group_id']) { |
218
|
|
|
$delete = false; |
219
|
|
|
} |
220
|
|
|
} |
221
|
|
|
if ($delete) { |
222
|
|
|
AnnouncementManager::delete_announcement($courseInfo, $itemId); |
223
|
|
|
} |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
} |
227
|
|
|
} |
228
|
|
|
break; |
229
|
|
|
default: |
230
|
|
|
echo ''; |
231
|
|
|
break; |
232
|
|
|
} |
233
|
|
|
exit; |
234
|
|
|
|