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/cron/agenda_reminders.php b/main/cron/agenda_reminders.php
index c07f4717ff..b50f17f38e 100644
--- a/main/cron/agenda_reminders.php
+++ b/main/cron/agenda_reminders.php
@@ -25,10 +25,16 @@ $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());
+ if (null === $event) {
+ continue;
+ }
+
$notificationDate = clone $event->getDate();
$notificationDate->sub($reminder->getDateInterval());
@@ -37,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)
);
}
@@ -60,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(),
@@ -86,6 +92,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();
@@ -96,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)
);
}
@@ -118,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());
@@ -139,19 +154,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']
+ );
}
}
}
diff --git a/main/inc/lib/agenda.lib.php b/main/inc/lib/agenda.lib.php
index 302613bb08..18ab499e2c 100644
--- a/main/inc/lib/agenda.lib.php
+++ b/main/inc/lib/agenda.lib.php
@@ -924,233 +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
- );
+ // 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
+ );
+ }
+ }
- // Add groups
- if (!empty($groupToAdd)) {
- foreach ($groupToAdd as $group) {
- $groupInfoItem = [];
- if ($group) {
- $groupInfoItem = GroupManager::get_group_properties(
- $group
- );
- }
+ // 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_update(
- $this->course,
- TOOL_CALENDAR_EVENT,
- $id,
- 'visible',
- $authorId,
- $groupInfoItem,
- 0,
- $start,
- $end,
- $this->sessionId
+ // Add groups
+ if (!empty($groupToAdd)) {
+ foreach ($groupToAdd as $group) {
+ $groupInfoItem = [];
+ if ($group) {
+ $groupInfoItem = GroupManager::get_group_properties(
+ $group
);
}
- }
- // 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_update(
+ $this->course,
+ TOOL_CALENDAR_EVENT,
+ $id,
+ 'visible',
+ $authorId,
+ $groupInfoItem,
+ 0,
+ $start,
+ $end,
+ $this->sessionId
+ );
+ }
+ }
- api_item_property_delete(
- $this->course,
- TOOL_CALENDAR_EVENT,
- $id,
- 0,
- $groupIidItem,
- $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
+ );
}
+ }
- // 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 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 users.
- if (!empty($usersToDelete)) {
- foreach ($usersToDelete as $userId) {
- api_item_property_delete(
- $this->course,
- TOOL_CALENDAR_EVENT,
- $id,
- $userId,
- $groupInfo,
- $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 announcement.
- if (isset($addAnnouncement) && !empty($addAnnouncement)) {
- $this->storeAgendaEventAsAnnouncement(
- $id,
- $usersToSend
- );
- }
+ // Add announcement.
+ if (isset($addAnnouncement) && !empty($addAnnouncement)) {
+ $this->storeAgendaEventAsAnnouncement(
+ $id,
+ $usersToSend
+ );
+ }
- // Add attachment.
- if (isset($attachmentArray) && !empty($attachmentArray)) {
- $counter = 0;
- foreach ($attachmentArray as $attachmentItem) {
- $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':
@@ -1176,6 +1178,8 @@ class Agenda
}
$this->editReminders($id, $remindersList);
+
+ return true;
}
/**
@@ -1473,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;