diff --git a/main/announcements/announcements.php b/main/announcements/announcements.php index a571a30bb3..ab198f72bc 100755 --- a/main/announcements/announcements.php +++ b/main/announcements/announcements.php @@ -732,6 +732,18 @@ switch ($action) { $form->addHtml(''); if ($showSubmitButton) { @@ -758,6 +770,11 @@ switch ($action) { } $sendMeCopy = isset($data['send_me_a_copy_by_email']) ? true : false; + $notificationCount = $data['notification_count'] ?? []; + $notificationPeriod = $data['notification_period'] ?? []; + + $reminders = $notificationCount ? array_map(null, $notificationCount, $notificationPeriod) : []; + if (isset($id) && $id) { // there is an Id => the announcement already exists => update mode if (Security::check_token('post')) { @@ -779,7 +796,8 @@ switch ($action) { $id, $data['event_date_start'], $data['event_date_end'], - empty($data['users']) ? ['everyone'] : $data['users'] + empty($data['users']) ? ['everyone'] : $data['users'], + $reminders ); } @@ -867,7 +885,8 @@ switch ($action) { $insert_id, $data['event_date_start'], $data['event_date_end'], - empty($data['users']) ? ['everyone'] : $data['users'] + empty($data['users']) ? ['everyone'] : $data['users'], + $reminders ); } diff --git a/main/calendar/agenda.php b/main/calendar/agenda.php index 2fb801c699..1ef34a6783 100755 --- a/main/calendar/agenda.php +++ b/main/calendar/agenda.php @@ -95,39 +95,10 @@ function add_image_form() { $agendaRemindersEnabled = api_get_configuration_value('agenda_reminders'); if ($agendaRemindersEnabled) { - $htmlHeadXtra[] = ''; + $htmlHeadXtra[] = '' + ; } // setting the name of the tool diff --git a/main/calendar/agenda_js.php b/main/calendar/agenda_js.php index 7117115320..7bff4f8e2d 100755 --- a/main/calendar/agenda_js.php +++ b/main/calendar/agenda_js.php @@ -279,6 +279,11 @@ if ('course' === $agenda->type) { $form->addElement('checkbox', 'add_as_annonuncement', null, get_lang('AddAsAnnouncement')); $form->addHtml(''); $form->addElement('textarea', 'comment', get_lang('Comment'), ['id' => 'comment']); + + $tpl->assign( + 'agenda_reminders_js', + Agenda::getJsForReminders('#form_add_notification') + ); } if (api_get_configuration_value('agenda_collective_invitations') && 'personal' === $agenda->type) { diff --git a/main/inc/lib/AnnouncementManager.php b/main/inc/lib/AnnouncementManager.php index b71a850d93..b190b57913 100755 --- a/main/inc/lib/AnnouncementManager.php +++ b/main/inc/lib/AnnouncementManager.php @@ -2238,7 +2238,8 @@ class AnnouncementManager int $announcementId, string $startDate, string $endDate, - array $choosenUsers = [] + array $choosenUsers = [], + array $reminders = [] ): ?CCalendarEvent { $em = Database::getManager(); $announcement = $em->find('ChamiloCourseBundle:CAnnouncement', $announcementId); @@ -2256,7 +2257,10 @@ class AnnouncementManager [], [], null, - '' + '', + [], + false, + $reminders ); if ($eventId) { diff --git a/main/inc/lib/agenda.lib.php b/main/inc/lib/agenda.lib.php index 5c0b558d5d..a795625545 100644 --- a/main/inc/lib/agenda.lib.php +++ b/main/inc/lib/agenda.lib.php @@ -4557,6 +4557,40 @@ class Agenda $em->flush(); } + public static function getJsForReminders(string $cssSelectorBtnAdd): string + { + return ' + var template = \'
\' + + \'
\' + + \'\' + + \'
\' + + \'
\' + + \'\' + + \'
\' + + \'

'.get_lang('Before').'

\' + + \'
\' + + \'\' + + \'
\' + + \'
\'; + + $("'.$cssSelectorBtnAdd.'").on("click", function (e) { + e.preventDefault(); + + $(template).appendTo("#notification_list"); + $("#notification_list select").selectpicker("refresh"); + }); + + $("#notification_list").on("click", ".delete-notification", function (e) { + e.preventDefault(); + + $(this).parents(".form-group").remove(); + });'; + } + private function editReminders(int $eventId, array $reminderList = []) { if (false === api_get_configuration_value('agenda_reminders')) { diff --git a/main/template/default/agenda/month.tpl b/main/template/default/agenda/month.tpl index 179c14c051..831bc285ee 100755 --- a/main/template/default/agenda/month.tpl +++ b/main/template/default/agenda/month.tpl @@ -927,37 +927,7 @@ $(function() { } }); - {% if 'agenda_reminders'|api_get_configuration_value %} - var template = '
' + - '
' + - '' + - '
' + - '
' + - '' + - '
' + - '

{{ 'Before'|get_lang }}

' + - '
' + - '' + - '
' + - '
'; - - $('#form_add_notification').on('click', function (e) { - e.preventDefault(); - - $(template).appendTo('#notification_list'); - $('#notification_list select').selectpicker('refresh'); - }); - - $('#notification_list').on('click', '.delete-notification', function (e) { - e.preventDefault(); - - $(this).parents('.form-group').remove(); - }); - {% endif %} + {{ agenda_reminders_js }} }); {{ actions_div }}