28if (!defined(
'NOREQUIREUSER')) {
29 define(
'NOREQUIREUSER',
'1');
31if (!defined(
'NOREQUIRESOC')) {
32 define(
'NOREQUIRESOC',
'1');
34if (!defined(
'NOCSRFCHECK')) {
35 define(
'NOCSRFCHECK', 1);
37if (!defined(
'NOTOKENRENEWAL')) {
38 define(
'NOTOKENRENEWAL', 1);
40if (!defined(
'NOLOGIN')) {
43if (!defined(
'NOREQUIREMENU')) {
44 define(
'NOREQUIREMENU', 1);
46if (!defined(
'NOREQUIREHTML')) {
47 define(
'NOREQUIREHTML', 1);
50session_cache_limiter(
'public');
52require_once
'../../main.inc.php';
63if (empty($dolibarr_nocache)) {
64 header(
'Cache-Control: max-age=10800, public, must-revalidate');
66 header(
'Cache-Control: no-cache');
70print
"jQuery(document).ready(function () {\n";
74print
' var nowtime = Date.now();';
75print
' var time_auto_update = '.max(1,
getDolGlobalInt(
'MAIN_BROWSER_NOTIFICATION_FREQUENCY')).
';'.
"\n";
76print
' var time_js_next_test;'.
"\n";
77print
' var dolnotif_nb_test_for_page = 0;'.
"\n";
78print
' var dolnotif_idinterval = null;'.
"\n";
82if (
"Notification" in window) {
84 if (Notification.permission !==
"granted") {
85 console.log(
"Ask Notification.permission");
86 Notification.requestPermission(
function(result) {
87 console.log(
"result for Notification.requestPermission is "+result);
95 var time_first_execution = <?php echo max(3,
getDolGlobalInt(
'MAIN_BROWSER_NOTIFICATION_CHECK_FIRST_EXECUTION', 0)); ?>;
97 setTimeout(first_execution, time_first_execution * 1000);
98 time_js_next_test = nowtime + time_first_execution;
99 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);
101 console.log(
"This browser in this context does not support Notification.");
105function first_execution() {
106 console.log(
"Call first_execution of check_events()");
107 result = check_events();
109 console.log(
"check_events() is scheduled as a repeated task with a time_auto_update = MAIN_BROWSER_NOTIFICATION_FREQUENCY = "+time_auto_update+
"s");
110 dolnotif_idinterval = setInterval(check_events, time_auto_update * 1000);
115function check_events() {
117 dolnotif_nb_test_for_page += 1;
118 var methodfornotification =
'<?php print getDolUserString('AGENDA_NOTIFICATION_METHOD
', getDolGlobalString('AGENDA_NOTIFICATION_METHOD
', 'jnotify
')); ?>';
121 if (methodfornotification ==
"jsnotification" && Notification.permission ==
"granted") {
124 if (methodfornotification ==
"jnotify") {
128 if (permissionok == 1) {
130 const allMeta = document.getElementsByTagName(
"meta");
131 for (let i = 0; i < allMeta.length; i++) {
132 if (allMeta[i].getAttribute(
"name") ==
'anti-csrf-currenttoken') {
137 time_js_next_test += time_auto_update;
139 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);
141 $.ajax(
"<?php print DOL_URL_ROOT.'/core/ajax/check_notifications.php'; ?>", {
144 data: { time_js_next_test: time_js_next_test, forcechecknow: 1, token:
currentToken, dolnotif_nb_test_for_page: dolnotif_nb_test_for_page },
146 success:
function (result) {
148 var arrayofpastreminders = Object.values(result.pastreminders);
149 if (arrayofpastreminders && arrayofpastreminders.length > 0) {
150 console.log(
"Retrieved "+arrayofpastreminders.length+
" reminders to do.");
154 print
'audio = new Audio(\''.DOL_URL_ROOT.
'/theme/common/sound/notification_agenda.wav\');';
157 var icon =
'<?php print DOL_URL_ROOT.'/theme/common/octicons/build/svg/bell.svg
'; ?>';
158 var listofreminderids =
'';
161 $.each(arrayofpastreminders,
function (index, value) {
163 var url =
"notdefined";
164 var title =
"Not defined";
167 if (value.type ==
'agenda')
169 url =
'<?php print DOL_URL_ROOT.'/comm/action/card.php?id=
'; ?>' + value.id_agenda;
170 title =
'<?php print dol_escape_js($langs->transnoentities('EventReminder
')) ?>';
173 if (methodfornotification ==
"jsnotification") {
175 if (value.type ==
'agenda' && value.location !=
null && value.location !=
'') {
176 body +=
'\n' + value.location;
179 if (value.type ==
'agenda' && (value.event_date_start_formated !=
null || value.event_date_start_formated[
'event_date_start'] !=
'')) {
180 body +=
'\n' + value.event_date_start_formated;
183 if (title !=
"Not defined") {
184 body = title+
'<br><br>';
186 body +=
'<img src="'+icon+
'">';
187 if (value.type ==
'agenda' && (value.event_date_start_formated !=
null || value.event_date_start_formated[
'event_date_start'] !=
'')) {
188 body +=
' '+value.event_date_start_formated;
190 body +=
' - <a href="'+url+
'"><?php echo img_picto("", "url", 'class=
"pictofixedwidth"').dol_escape_js($langs->trans("ShowDetails")); ?></a>';
191 body +=
'<br>'+value.label;
192 if (value.type ==
'agenda' && value.location !=
null && value.location !=
'') {
193 body +=
'<br>' + value.location;
198 console.log(
"Send notification on browser url="+url+
" using method="+methodfornotification);
201 if (methodfornotification ==
'jsnotification') {
205 lang:
'<?php print dol_escape_js($langs->getDefaultLang(1)); ?>',
206 tag: value.id_agenda,
207 requireInteraction:
true
212 noti[index] =
new Notification(title, extra);
213 if (index==0 && audio)
219 noti[index].onclick =
function (event) {
221 console.log(
"A click on notification on browser has been done for url="+url);
222 event.preventDefault();
224 window.open(url,
'_blank');
228 listofreminderids = (listofreminderids ==
'' ?
'' : listofreminderids +
',') + value.id_reminder
233 if (methodfornotification ==
'jnotify') {
235 $.jnotify(body,
'warning',
true, {
remove:
function (){} } );
237 listofreminderids = (listofreminderids ==
'' ?
'' : listofreminderids +
',') + value.id_reminder
242 if (listofreminderids !=
'') {
243 console.log(
"Flag notification as done for listofreminderids="+listofreminderids);
244 $.ajax(
"<?php print DOL_URL_ROOT.'/core/ajax/check_notifications.php?action=stopreminder&listofreminderids='; ?>"+listofreminderids, {
247 data: { time_js_next_test: time_js_next_test, token:
currentToken }
251 console.log(
"No remind to do found, next search at "+time_js_next_test);
258 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).");
263 if (dolnotif_nb_test_for_page >= 5) {
264 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);
265 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