22 if (!defined(
'NOREQUIREUSER')) {
23 define(
'NOREQUIREUSER',
'1');
25 if (!defined(
'NOREQUIRESOC')) {
26 define(
'NOREQUIRESOC',
'1');
28 if (!defined(
'NOCSRFCHECK')) {
29 define(
'NOCSRFCHECK', 1);
31 if (!defined(
'NOTOKENRENEWAL')) {
32 define(
'NOTOKENRENEWAL', 1);
34 if (!defined(
'NOLOGIN')) {
37 if (!defined(
'NOREQUIREMENU')) {
38 define(
'NOREQUIREMENU', 1);
40 if (!defined(
'NOREQUIREHTML')) {
41 define(
'NOREQUIREHTML', 1);
44 session_cache_limiter(
'public');
46 require_once
'../../main.inc.php';
55 if (empty($dolibarr_nocache)) {
56 header(
'Cache-Control: max-age=10800, public, must-revalidate');
58 header(
'Cache-Control: no-cache');
62 print
"jQuery(document).ready(function () {\n";
66 print
' var nowtime = Date.now();';
67 print
' var time_auto_update = '.max(1,
getDolGlobalInt(
'MAIN_BROWSER_NOTIFICATION_FREQUENCY')).
';'.
"\n";
68 print
' var time_js_next_test;'.
"\n";
72 if (
"Notification" in window) {
74 if (Notification.permission !==
"granted") {
75 console.log(
"Ask Notification.permission");
76 Notification.requestPermission()
83 var time_first_execution = <?php echo max(3, empty($conf->global->MAIN_BROWSER_NOTIFICATION_CHECK_FIRST_EXECUTION) ? 0 : $conf->global->MAIN_BROWSER_NOTIFICATION_CHECK_FIRST_EXECUTION); ?>;
85 setTimeout(first_execution, time_first_execution * 1000);
86 time_js_next_test = nowtime + time_first_execution;
87 console.log(
"Launch browser notif check: setTimeout is set to launch 'first_execution' function after a wait of time_first_execution="+time_first_execution+
". nowtime (time php page generation) = "+nowtime+
" time_js_next_check = "+time_js_next_test);
89 console.log(
"This browser in this context does not support Notification.");
93 function first_execution() {
94 console.log(
"Call first_execution then set repeat time to time_auto_update = MAIN_BROWSER_NOTIFICATION_FREQUENCY = "+time_auto_update);
96 setInterval(check_events, time_auto_update * 1000);
99 function check_events() {
100 if (Notification.permission ===
"granted")
102 time_js_next_test += time_auto_update;
103 console.log(
"Call ajax to check_events with time_js_next_test = "+time_js_next_test);
105 $.ajax(
"<?php print DOL_URL_ROOT.'/core/ajax/check_notifications.php'; ?>", {
108 data: { time_js_next_test: time_js_next_test, forcechecknow: 1, token:
'notrequired' },
110 success:
function (result) {
112 var arrayofpastreminders = Object.values(result.pastreminders);
113 if (arrayofpastreminders && arrayofpastreminders.length > 0) {
114 console.log(
"Retrieved "+arrayofpastreminders.length+
" reminders to do.");
117 if (!empty($conf->global->AGENDA_REMINDER_BROWSER_SOUND)) {
118 print
'audio = new Audio(\''.DOL_URL_ROOT.
'/theme/common/sound/notification_agenda.wav\');';
121 var listofreminderids =
'';
124 $.each(arrayofpastreminders,
function (index, value) {
126 var url =
"notdefined";
127 var title =
"Not defined";
128 var body = value.label;
129 if (value.type ==
'agenda' && value.location !=
null && value.location !=
'') {
130 body +=
'\n' + value.location;
133 if (value.type ==
'agenda' && (value.event_date_start_formated !=
null || value.event_date_start_formated[
'event_date_start'] !=
'')) {
134 body +=
'\n' + value.event_date_start_formated;
137 if (value.type ==
'agenda')
139 url =
'<?php print DOL_URL_ROOT.'/comm/action/card.php?id=
'; ?>' + value.id_agenda;
140 title =
'<?php print dol_escape_js($langs->transnoentities('EventReminder
')) ?>';
143 icon:
'<?php print DOL_URL_ROOT.'/theme/common/bell.png
'; ?>',
146 tag: value.id_agenda,
147 requireInteraction: true
151 console.log(
"Send notification on browser");
152 noti[index] =
new Notification(title, extra);
153 if (index==0 && audio)
159 noti[index].onclick =
function (event) {
160 console.log(
"A click on notification on browser has been done");
161 event.preventDefault();
163 window.open(url,
'_blank');
167 listofreminderids = (listofreminderids ==
'' ?
'' : listofreminderids +
',') + value.id_reminder
172 console.log(
"Flag notification as done for listofreminderids="+listofreminderids);
173 $.ajax(
"<?php print DOL_URL_ROOT.'/core/ajax/check_notifications.php?action=stopreminder&listofreminderids='; ?>"+listofreminderids, {
176 data: { time_js_next_test: time_js_next_test, token:
'notrequired' }
179 console.log(
"No reminder to do found, next search at "+time_js_next_test);
186 console.log(
"Cancel check_events. Useless because javascript Notification.permission is "+Notification.permission+
" (blocked manualy or web site is not https).");