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, !
getDolGlobalString(
'MAIN_BROWSER_NOTIFICATION_CHECK_FIRST_EXECUTION') ? 0 : $conf->global->MAIN_BROWSER_NOTIFICATION_CHECK_FIRST_EXECUTION); ?>;
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;
116 if (Notification.permission ===
"granted") {
118 const allMeta = document.getElementsByTagName(
"meta");
119 for (let i = 0; i < allMeta.length; i++) {
120 if (allMeta[i].getAttribute(
"name") ==
'anti-csrf-currenttoken') {
125 time_js_next_test += time_auto_update;
127 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);
129 $.ajax(
"<?php print DOL_URL_ROOT.'/core/ajax/check_notifications.php'; ?>", {
132 data: { time_js_next_test: time_js_next_test, forcechecknow: 1, token:
currentToken, dolnotif_nb_test_for_page: dolnotif_nb_test_for_page },
134 success:
function (result) {
136 var arrayofpastreminders = Object.values(result.pastreminders);
137 if (arrayofpastreminders && arrayofpastreminders.length > 0) {
138 console.log(
"Retrieved "+arrayofpastreminders.length+
" reminders to do.");
142 print
'audio = new Audio(\''.DOL_URL_ROOT.
'/theme/common/sound/notification_agenda.wav\');';
145 var listofreminderids =
'';
148 $.each(arrayofpastreminders,
function (index, value) {
150 var url =
"notdefined";
151 var title =
"Not defined";
152 var body = value.label;
153 var icon =
'<?php print DOL_URL_ROOT.'/theme/common/octicons/build/svg/bell.svg
'; ?>';
154 var image =
'<?php print DOL_URL_ROOT.'/theme/common/octicons/build/svg/bell.svg
'; ?>';
155 if (value.type ==
'agenda' && value.location !=
null && value.location !=
'') {
156 body +=
'\n' + value.location;
159 if (value.type ==
'agenda' && (value.event_date_start_formated !=
null || value.event_date_start_formated[
'event_date_start'] !=
'')) {
160 body +=
'\n' + value.event_date_start_formated;
163 if (value.type ==
'agenda')
165 url =
'<?php print DOL_URL_ROOT.'/comm/action/card.php?id=
'; ?>' + value.id_agenda;
166 title =
'<?php print dol_escape_js($langs->transnoentities('EventReminder
')) ?>';
171 lang:
'<?php print dol_escape_js($langs->getDefaultLang(1)); ?>',
172 tag: value.id_agenda,
173 requireInteraction: true
179 console.log(
"Send notification on browser url="+url);
180 noti[index] =
new Notification(title, extra);
181 if (index==0 && audio)
187 noti[index].onclick =
function (event) {
189 console.log(
"A click on notification on browser has been done for url="+url);
190 event.preventDefault();
192 window.open(url,
'_blank');
196 listofreminderids = (listofreminderids ==
'' ?
'' : listofreminderids +
',') + value.id_reminder
201 console.log(
"Flag notification as done for listofreminderids="+listofreminderids);
202 $.ajax(
"<?php print DOL_URL_ROOT.'/core/ajax/check_notifications.php?action=stopreminder&listofreminderids='; ?>"+listofreminderids, {
205 data: { time_js_next_test: time_js_next_test, token:
currentToken }
208 console.log(
"No remind to do found, next search at "+time_js_next_test);
215 console.log(
"Cancel check_events() with dolnotif_nb_test_for_page="+dolnotif_nb_test_for_page+
". Check is useless because javascript Notification.permission is "+Notification.permission+
" (blocked manually or web site is not https or browser is in Private mode).");
220 if (dolnotif_nb_test_for_page >= 5) {
221 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);
222 clearInterval(dolnotif_idinterval);
currentToken()
Return the value of token currently saved into session with name 'token'.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolGlobalString($key, $default='')
Return 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