27if (!defined(
'NOREQUIREUSER')) {
28 define(
'NOREQUIREUSER',
'1');
30if (!defined(
'NOREQUIRESOC')) {
31 define(
'NOREQUIRESOC',
'1');
33if (!defined(
'NOCSRFCHECK')) {
34 define(
'NOCSRFCHECK', 1);
36if (!defined(
'NOTOKENRENEWAL')) {
37 define(
'NOTOKENRENEWAL', 1);
39if (!defined(
'NOLOGIN')) {
42if (!defined(
'NOREQUIREMENU')) {
43 define(
'NOREQUIREMENU', 1);
45if (!defined(
'NOREQUIREHTML')) {
46 define(
'NOREQUIREHTML', 1);
49session_cache_limiter(
'public');
51require_once
'../../main.inc.php';
60if (empty($dolibarr_nocache)) {
61 header(
'Cache-Control: max-age=10800, public, must-revalidate');
63 header(
'Cache-Control: no-cache');
67print
"jQuery(document).ready(function () {\n";
71print
' var nowtime = Date.now();';
72print
' var time_auto_update = '.max(1,
getDolGlobalInt(
'MAIN_BROWSER_NOTIFICATION_FREQUENCY')).
';'.
"\n";
73print
' var time_js_next_test;'.
"\n";
74print
' var dolnotif_nb_test_for_page = 0;'.
"\n";
75print
' var dolnotif_idinterval = null;'.
"\n";
79if (
"Notification" in window) {
81 if (Notification.permission !==
"granted") {
82 console.log(
"Ask Notification.permission");
83 Notification.requestPermission(
function(result) {
84 console.log(
"result for Notification.requestPermission is "+result);
92 var time_first_execution = <?php echo max(3,
getDolGlobalInt(
'MAIN_BROWSER_NOTIFICATION_CHECK_FIRST_EXECUTION', 0)); ?>;
94 setTimeout(first_execution, time_first_execution * 1000);
95 time_js_next_test = nowtime + time_first_execution;
96 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);
98 console.log(
"This browser in this context does not support Notification.");
102function first_execution() {
103 console.log(
"Call first_execution of check_events()");
104 result = check_events();
106 console.log(
"check_events() is scheduled as a repeated task with a time_auto_update = MAIN_BROWSER_NOTIFICATION_FREQUENCY = "+time_auto_update+
"s");
107 dolnotif_idinterval = setInterval(check_events, time_auto_update * 1000);
112function check_events() {
114 dolnotif_nb_test_for_page += 1;
115 var methodfornotification =
'<?php print getDolUserString('AGENDA_NOTIFICATION_METHOD
', getDolGlobalString('AGENDA_NOTIFICATION_METHOD
', 'jnotify
')); ?>';
118 if (methodfornotification ==
"jsnotification" && Notification.permission ==
"granted") {
121 if (methodfornotification ==
"jnotify") {
125 if (permissionok == 1) {
127 const allMeta = document.getElementsByTagName(
"meta");
128 for (let i = 0; i < allMeta.length; i++) {
129 if (allMeta[i].getAttribute(
"name") ==
'anti-csrf-currenttoken') {
134 time_js_next_test += time_auto_update;
136 console.log(
"Call ajax to check events with time_js_next_test = "+time_js_next_test+
" dolnotif_nb_test_for_page="+dolnotif_nb_test_for_page);
138 $.ajax(
"<?php print DOL_URL_ROOT.'/core/ajax/check_notifications.php'; ?>", {
141 data: { time_js_next_test: time_js_next_test, forcechecknow: 1, token:
currentToken, dolnotif_nb_test_for_page: dolnotif_nb_test_for_page },
143 success:
function (result) {
145 var arrayofpastreminders = Object.values(result.pastreminders);
146 if (arrayofpastreminders && arrayofpastreminders.length > 0) {
147 console.log(
"Retrieved "+arrayofpastreminders.length+
" reminders to do.");
151 print
'audio = new Audio(\''.DOL_URL_ROOT.
'/theme/common/sound/notification_agenda.wav\');';
154 var icon =
'<?php print DOL_URL_ROOT.'/theme/common/octicons/build/svg/bell.svg
'; ?>';
155 var listofreminderids =
'';
158 $.each(arrayofpastreminders,
function (index, value) {
160 var url =
"notdefined";
161 var title =
"Not defined";
164 if (value.type ==
'agenda')
166 url =
'<?php print DOL_URL_ROOT.'/comm/action/card.php?id=
'; ?>' + value.id_agenda;
167 title =
'<?php print dol_escape_js($langs->transnoentities('EventReminder
')) ?>';
170 if (methodfornotification ==
"jsnotification") {
172 if (value.type ==
'agenda' && value.location !=
null && value.location !=
'') {
173 body +=
'\n' + value.location;
176 if (value.type ==
'agenda' && (value.event_date_start_formated !=
null || value.event_date_start_formated[
'event_date_start'] !=
'')) {
177 body +=
'\n' + value.event_date_start_formated;
180 if (title !=
"Not defined") {
181 body = title+
'<br><br>';
183 body +=
'<img src="'+icon+
'">';
184 if (value.type ==
'agenda' && (value.event_date_start_formated !=
null || value.event_date_start_formated[
'event_date_start'] !=
'')) {
185 body +=
' '+value.event_date_start_formated;
187 body +=
' - <a href="'+url+
'"><?php echo img_picto("", "url", 'class=
"pictofixedwidth"').dol_escape_js($langs->trans("ShowDetails")); ?></a>';
188 body +=
'<br>'+value.label;
189 if (value.type ==
'agenda' && value.location !=
null && value.location !=
'') {
190 body +=
'<br>' + value.location;
195 console.log(
"Send notification on browser url="+url+
" using method="+methodfornotification);
198 if (methodfornotification ==
'jsnotification') {
202 lang:
'<?php print dol_escape_js($langs->getDefaultLang(1)); ?>',
203 tag: value.id_agenda,
204 requireInteraction:
true
209 noti[index] =
new Notification(title, extra);
210 if (index==0 && audio)
216 noti[index].onclick =
function (event) {
218 console.log(
"A click on notification on browser has been done for url="+url);
219 event.preventDefault();
221 window.open(url,
'_blank');
225 listofreminderids = (listofreminderids ==
'' ?
'' : listofreminderids +
',') + value.id_reminder
230 if (methodfornotification ==
'jnotify') {
232 $.jnotify(body,
'warning',
true, {
remove:
function (){} } );
234 listofreminderids = (listofreminderids ==
'' ?
'' : listofreminderids +
',') + value.id_reminder
239 if (listofreminderids !=
'') {
240 console.log(
"Flag notification as done for listofreminderids="+listofreminderids);
241 $.ajax(
"<?php print DOL_URL_ROOT.'/core/ajax/check_notifications.php?action=stopreminder&listofreminderids='; ?>"+listofreminderids, {
244 data: { time_js_next_test: time_js_next_test, token:
currentToken }
248 console.log(
"No remind to do found, next search at "+time_js_next_test);
255 console.log(
"Cancel check_events() with dolnotif_nb_test_for_page="+dolnotif_nb_test_for_page+
". Check is useless because permission is off. Javascript Notification.permission is "+Notification.permission+
" (blocked manually or web site is not https or browser is in Private mode).");
260 if (dolnotif_nb_test_for_page >= 5) {
261 console.log(
"We did "+dolnotif_nb_test_for_page+
" consecutive test on this page. We stop checking now from here by clearing dolnotif_idinterval="+dolnotif_idinterval);
262 clearInterval(dolnotif_idinterval);
currentToken()
Return the value of token currently saved into session with name 'token'.
getDolUserString($key, $default='', $tmpuser=null)
Return Dolibarr user constant string value.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type