From 82b22e9e89f97d8acb486dc8669dac178158adcc Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 4 Jan 2022 16:29:00 -0500 Subject: [PATCH 1/6] Agenda: Validate attachment to update in course event - refs BT#19392 --- main/calendar/agenda.php | 2 +- main/inc/lib/agenda.lib.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/main/calendar/agenda.php b/main/calendar/agenda.php index e1ca3dd566..2fb801c699 100755 --- a/main/calendar/agenda.php +++ b/main/calendar/agenda.php @@ -272,7 +272,7 @@ if ($allowToEdit) { $endDate = $values['date_range_end']; $sendAttachment = isset($_FILES) && !empty($_FILES); - $attachmentList = $sendAttachment ? $_FILES : null; + $attachmentList = $sendAttachment ? $_FILES : []; $attachmentCommentList = $values['legend'] ?? ''; $comment = $values['comment'] ?? ''; $notificationCount = $_REQUEST['notification_count'] ?? []; diff --git a/main/inc/lib/agenda.lib.php b/main/inc/lib/agenda.lib.php index 302613bb08..4cb84cb2df 100644 --- a/main/inc/lib/agenda.lib.php +++ b/main/inc/lib/agenda.lib.php @@ -1137,6 +1137,10 @@ class Agenda if (isset($attachmentArray) && !empty($attachmentArray)) { $counter = 0; foreach ($attachmentArray as $attachmentItem) { + if (empty($attachmentItems['id'])) { + continue; + } + $this->updateAttachment( $attachmentItem['id'], $id, From 5d5ced6db2913e0fe94b8973bce3e67df265ff92 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 4 Jan 2022 16:41:28 -0500 Subject: [PATCH 2/6] Agenda: Fix update reminders in course event - refs BT#19392 --- main/inc/lib/agenda.lib.php | 398 ++++++++++++++++++------------------ 1 file changed, 199 insertions(+), 199 deletions(-) diff --git a/main/inc/lib/agenda.lib.php b/main/inc/lib/agenda.lib.php index 4cb84cb2df..7748dcf8c6 100644 --- a/main/inc/lib/agenda.lib.php +++ b/main/inc/lib/agenda.lib.php @@ -924,237 +924,235 @@ class Agenda return false; } - if ($this->getIsAllowedToEdit()) { - $attributes = [ - 'title' => $title, - 'start_date' => $start, - 'end_date' => $end, - 'all_day' => $allDay, - 'comment' => $comment, - ]; + if (!$this->getIsAllowedToEdit()) { + return false; + } - if ($updateContent) { - $attributes['content'] = $content; - } + $attributes = [ + 'title' => $title, + 'start_date' => $start, + 'end_date' => $end, + 'all_day' => $allDay, + 'comment' => $comment, + ]; - if (!empty($color)) { - $attributes['color'] = $color; - } + if ($updateContent) { + $attributes['content'] = $content; + } - Database::update( - $this->tbl_course_agenda, - $attributes, - [ - 'id = ? AND c_id = ? AND session_id = ? ' => [ - $id, - $courseId, - $this->sessionId, - ], - ] - ); + if (!empty($color)) { + $attributes['color'] = $color; + } - if (!empty($usersToSend)) { - $sendTo = $this->parseSendToArray($usersToSend); + Database::update( + $this->tbl_course_agenda, + $attributes, + [ + 'id = ? AND c_id = ? AND session_id = ? ' => [ + $id, + $courseId, + $this->sessionId, + ], + ] + ); - $usersToDelete = array_diff( - $eventInfo['send_to']['users'], - $sendTo['users'] - ); - $usersToAdd = array_diff( - $sendTo['users'], - $eventInfo['send_to']['users'] - ); + if (!empty($usersToSend)) { + $sendTo = $this->parseSendToArray($usersToSend); - $groupsToDelete = array_diff( - $eventInfo['send_to']['groups'], - $sendTo['groups'] - ); - $groupToAdd = array_diff( - $sendTo['groups'], - $eventInfo['send_to']['groups'] - ); + $usersToDelete = array_diff( + $eventInfo['send_to']['users'], + $sendTo['users'] + ); + $usersToAdd = array_diff( + $sendTo['users'], + $eventInfo['send_to']['users'] + ); - if ($sendTo['everyone']) { - // Delete all from group - if (isset($eventInfo['send_to']['groups']) && - !empty($eventInfo['send_to']['groups']) - ) { - foreach ($eventInfo['send_to']['groups'] as $group) { - $groupIidItem = 0; - if ($group) { - $groupInfoItem = GroupManager::get_group_properties( - $group - ); - if ($groupInfoItem) { - $groupIidItem = $groupInfoItem['iid']; - } - } + $groupsToDelete = array_diff( + $eventInfo['send_to']['groups'], + $sendTo['groups'] + ); + $groupToAdd = array_diff( + $sendTo['groups'], + $eventInfo['send_to']['groups'] + ); - api_item_property_delete( - $this->course, - TOOL_CALENDAR_EVENT, - $id, - 0, - $groupIidItem, - $this->sessionId + if ($sendTo['everyone']) { + // Delete all from group + if (isset($eventInfo['send_to']['groups']) && + !empty($eventInfo['send_to']['groups']) + ) { + foreach ($eventInfo['send_to']['groups'] as $group) { + $groupIidItem = 0; + if ($group) { + $groupInfoItem = GroupManager::get_group_properties( + $group ); + if ($groupInfoItem) { + $groupIidItem = $groupInfoItem['iid']; + } } - } - // Storing the selected users. - if (isset($eventInfo['send_to']['users']) && - !empty($eventInfo['send_to']['users']) - ) { - foreach ($eventInfo['send_to']['users'] as $userId) { - api_item_property_delete( - $this->course, - TOOL_CALENDAR_EVENT, - $id, - $userId, - $groupIid, - $this->sessionId - ); - } + api_item_property_delete( + $this->course, + TOOL_CALENDAR_EVENT, + $id, + 0, + $groupIidItem, + $this->sessionId + ); } + } - // Add to everyone only. - api_item_property_update( - $this->course, - TOOL_CALENDAR_EVENT, - $id, - 'visible', - $authorId, - $groupInfo, - null, - $start, - $end, - $this->sessionId - ); - } else { - // Delete "everyone". - api_item_property_delete( - $this->course, - TOOL_CALENDAR_EVENT, - $id, - 0, - 0, - $this->sessionId - ); - - // Add groups - if (!empty($groupToAdd)) { - foreach ($groupToAdd as $group) { - $groupInfoItem = []; - if ($group) { - $groupInfoItem = GroupManager::get_group_properties( - $group - ); - } - - api_item_property_update( - $this->course, - TOOL_CALENDAR_EVENT, - $id, - 'visible', - $authorId, - $groupInfoItem, - 0, - $start, - $end, - $this->sessionId - ); - } + // Storing the selected users. + if (isset($eventInfo['send_to']['users']) && + !empty($eventInfo['send_to']['users']) + ) { + foreach ($eventInfo['send_to']['users'] as $userId) { + api_item_property_delete( + $this->course, + TOOL_CALENDAR_EVENT, + $id, + $userId, + $groupIid, + $this->sessionId + ); } + } - // Delete groups. - if (!empty($groupsToDelete)) { - foreach ($groupsToDelete as $group) { - $groupIidItem = 0; - $groupInfoItem = []; - if ($group) { - $groupInfoItem = GroupManager::get_group_properties( - $group - ); - if ($groupInfoItem) { - $groupIidItem = $groupInfoItem['iid']; - } - } + // Add to everyone only. + api_item_property_update( + $this->course, + TOOL_CALENDAR_EVENT, + $id, + 'visible', + $authorId, + $groupInfo, + null, + $start, + $end, + $this->sessionId + ); + } else { + // Delete "everyone". + api_item_property_delete( + $this->course, + TOOL_CALENDAR_EVENT, + $id, + 0, + 0, + $this->sessionId + ); - api_item_property_delete( - $this->course, - TOOL_CALENDAR_EVENT, - $id, - 0, - $groupIidItem, - $this->sessionId + // Add groups + if (!empty($groupToAdd)) { + foreach ($groupToAdd as $group) { + $groupInfoItem = []; + if ($group) { + $groupInfoItem = GroupManager::get_group_properties( + $group ); } + + api_item_property_update( + $this->course, + TOOL_CALENDAR_EVENT, + $id, + 'visible', + $authorId, + $groupInfoItem, + 0, + $start, + $end, + $this->sessionId + ); } + } - // Add users. - if (!empty($usersToAdd)) { - foreach ($usersToAdd as $userId) { - api_item_property_update( - $this->course, - TOOL_CALENDAR_EVENT, - $id, - 'visible', - $authorId, - $groupInfo, - $userId, - $start, - $end, - $this->sessionId + // Delete groups. + if (!empty($groupsToDelete)) { + foreach ($groupsToDelete as $group) { + $groupIidItem = 0; + $groupInfoItem = []; + if ($group) { + $groupInfoItem = GroupManager::get_group_properties( + $group ); + if ($groupInfoItem) { + $groupIidItem = $groupInfoItem['iid']; + } } + + api_item_property_delete( + $this->course, + TOOL_CALENDAR_EVENT, + $id, + 0, + $groupIidItem, + $this->sessionId + ); } + } - // Delete users. - if (!empty($usersToDelete)) { - foreach ($usersToDelete as $userId) { - api_item_property_delete( - $this->course, - TOOL_CALENDAR_EVENT, - $id, - $userId, - $groupInfo, - $this->sessionId - ); - } + // Add users. + if (!empty($usersToAdd)) { + foreach ($usersToAdd as $userId) { + api_item_property_update( + $this->course, + TOOL_CALENDAR_EVENT, + $id, + 'visible', + $authorId, + $groupInfo, + $userId, + $start, + $end, + $this->sessionId + ); } } - } - // Add announcement. - if (isset($addAnnouncement) && !empty($addAnnouncement)) { - $this->storeAgendaEventAsAnnouncement( - $id, - $usersToSend - ); + // Delete users. + if (!empty($usersToDelete)) { + foreach ($usersToDelete as $userId) { + api_item_property_delete( + $this->course, + TOOL_CALENDAR_EVENT, + $id, + $userId, + $groupInfo, + $this->sessionId + ); + } + } } + } - // Add attachment. - if (isset($attachmentArray) && !empty($attachmentArray)) { - $counter = 0; - foreach ($attachmentArray as $attachmentItem) { - if (empty($attachmentItems['id'])) { - continue; - } + // Add announcement. + if (isset($addAnnouncement) && !empty($addAnnouncement)) { + $this->storeAgendaEventAsAnnouncement( + $id, + $usersToSend + ); + } - $this->updateAttachment( - $attachmentItem['id'], - $id, - $attachmentItem, - $attachmentCommentList[$counter], - $this->course - ); - $counter++; + // Add attachment. + if (isset($attachmentArray) && !empty($attachmentArray)) { + $counter = 0; + foreach ($attachmentArray as $attachmentItem) { + if (empty($attachmentItems['id'])) { + continue; } - } - return true; - } else { - return false; + $this->updateAttachment( + $attachmentItem['id'], + $id, + $attachmentItem, + $attachmentCommentList[$counter], + $this->course + ); + $counter++; + } } break; case 'admin': @@ -1180,6 +1178,8 @@ class Agenda } $this->editReminders($id, $remindersList); + + return true; } /** From 82006a2fde2e7f37c44c97c2581fffce0927dd87 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 4 Jan 2022 17:32:53 -0500 Subject: [PATCH 3/6] Agenda: Validate if event exists when send reminder - refs BT#19392 --- main/cron/agenda_reminders.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/main/cron/agenda_reminders.php b/main/cron/agenda_reminders.php index c07f4717ff..8d6c66fdab 100644 --- a/main/cron/agenda_reminders.php +++ b/main/cron/agenda_reminders.php @@ -29,6 +29,10 @@ foreach ($reminders as $reminder) { if ('personal' === $reminder->getType()) { $event = $em->find('ChamiloCoreBundle:PersonalAgenda', $reminder->getEventId()); + if (null === $event) { + continue; + } + $notificationDate = clone $event->getDate(); $notificationDate->sub($reminder->getDateInterval()); @@ -86,6 +90,11 @@ foreach ($reminders as $reminder) { if ('course' === $reminder->getType()) { $event = $em->find('ChamiloCourseBundle:CCalendarEvent', $reminder->getEventId()); + + if (null === $event) { + continue; + } + $agenda = new Agenda('course'); $notificationDate = clone $event->getStartDate(); From 1e878ad8c813a4e913b0216fab5946c6f6377976 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 4 Jan 2022 17:34:03 -0500 Subject: [PATCH 4/6] Agenda: Fist platform admin send course event reminder - refs BT#19392 --- main/cron/agenda_reminders.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/main/cron/agenda_reminders.php b/main/cron/agenda_reminders.php index 8d6c66fdab..6854baf821 100644 --- a/main/cron/agenda_reminders.php +++ b/main/cron/agenda_reminders.php @@ -25,6 +25,8 @@ $remindersRepo = $em->getRepository('ChamiloCoreBundle:AgendaReminder'); $reminders = $remindersRepo->findBySent(false); +$firstAdmin = current(UserManager::get_all_administrators()); + foreach ($reminders as $reminder) { if ('personal' === $reminder->getType()) { $event = $em->find('ChamiloCoreBundle:PersonalAgenda', $reminder->getEventId()); @@ -148,19 +150,34 @@ foreach ($reminders as $reminder) { } foreach ($userIdList as $userId) { - MessageManager::send_message_simple($userId, $messageSubject, $messageContent); + MessageManager::send_message_simple( + $userId, + $messageSubject, + $messageContent, + $firstAdmin['user_id'] + ); } } else { foreach ($sendTo['groups'] as $groupId) { $groupUserList = GroupManager::get_users($groupId, false, null, null, false, $event->getSessionId()); foreach ($groupUserList as $groupUserId) { - MessageManager::send_message_simple($groupUserId, $messageSubject, $messageContent); + MessageManager::send_message_simple( + $groupUserId, + $messageSubject, + $messageContent, + $firstAdmin['user_id'] + ); } } foreach ($sendTo['users'] as $userId) { - MessageManager::send_message_simple($userId, $messageSubject, $messageContent); + MessageManager::send_message_simple( + $userId, + $messageSubject, + $messageContent, + $firstAdmin['user_id'] + ); } } } From 0b455c82019cc707b2f1b58e6cc3689d68d42aef Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 4 Jan 2022 17:46:19 -0500 Subject: [PATCH 5/6] Agenda: Improve reminder content - refs BT#19392 --- main/cron/agenda_reminders.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/main/cron/agenda_reminders.php b/main/cron/agenda_reminders.php index 6854baf821..b50f17f38e 100644 --- a/main/cron/agenda_reminders.php +++ b/main/cron/agenda_reminders.php @@ -43,19 +43,19 @@ foreach ($reminders as $reminder) { } $eventDetails = []; - $eventDetails[] = ''.$event->getTitle().''; + $eventDetails[] = '

'.$event->getTitle().'

'; if ($event->getAllDay()) { - $eventDetails[] = get_lang('AllDay'); + $eventDetails[] = '

'.get_lang('AllDay').'

'; } else { $eventDetails[] = sprintf( - get_lang('FromDateX'), + '

'.get_lang('FromDateX').'

', api_get_local_time($event->getDate(), null, null, false, true, true) ); if (!empty($event->getEnddate())) { $eventDetails[] = sprintf( - get_lang('UntilDateX'), + '

'.get_lang('UntilDateX').'

', api_get_local_time($event->getEnddate(), null, null, false, true, true) ); } @@ -66,7 +66,7 @@ foreach ($reminders as $reminder) { } $messageSubject = sprintf(get_lang('ReminderXEvent'), $event->getTitle()); - $messageContent = implode('
', $eventDetails); + $messageContent = implode(PHP_EOL, $eventDetails); MessageManager::send_message_simple( $event->getUser(), @@ -107,19 +107,19 @@ foreach ($reminders as $reminder) { } $eventDetails = []; - $eventDetails[] = ''.$event->getTitle().''; + $eventDetails[] = '

'.$event->getTitle().'

'; if ($event->getAllDay()) { - $eventDetails[] = get_lang('AllDay'); + $eventDetails[] = '

'.get_lang('AllDay').'

'; } else { $eventDetails[] = sprintf( - get_lang('FromDateX'), + '

'.get_lang('FromDateX').'

', api_get_local_time($event->getStartDate(), null, null, false, true, true) ); if (!empty($event->getEndDate())) { $eventDetails[] = sprintf( - get_lang('UntilDateX'), + '

'.get_lang('UntilDateX').'

', api_get_local_time($event->getEndDate(), null, null, false, true, true) ); } @@ -129,8 +129,12 @@ foreach ($reminders as $reminder) { $eventDetails[] = $event->getContent(); } + if (!empty($event->getComment())) { + $eventDetails[] = '

'.$event->getComment().'

'; + } + $messageSubject = sprintf(get_lang('ReminderXEvent'), $event->getTitle()); - $messageContent = implode('
', $eventDetails); + $messageContent = implode(PHP_EOL, $eventDetails); $courseInfo = api_get_course_info_by_id($event->getCId()); From a4b5cb692d6995162f9edbc880f36151598dddab Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Wed, 5 Jan 2022 10:10:51 -0500 Subject: [PATCH 6/6] Agenda: Fix load reminders for session event - refs BT#19392 --- main/inc/lib/agenda.lib.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main/inc/lib/agenda.lib.php b/main/inc/lib/agenda.lib.php index 7748dcf8c6..18ab499e2c 100644 --- a/main/inc/lib/agenda.lib.php +++ b/main/inc/lib/agenda.lib.php @@ -1477,7 +1477,10 @@ class Agenda $id = str_replace(['personal_', 'course_', 'session_'], '', $eventInfo['id']); $eventInfo['reminders'] = $this->parseEventReminders( - $this->getEventReminders($id, $eventInfo['type']) + $this->getEventReminders( + $id, + 'session' === $eventInfo['type'] ? 'course' : $eventInfo['type'] + ) ); return $eventInfo;